1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description( 25"Test numeric escapes in string literals - https://bugs.webkit.org/show_bug.cgi?id=51724" 26); 27 28function test(_stringLiteral, _nonStrictResult, _strictResult) 29{ 30 stringLiteral = '"' + _stringLiteral + '"'; 31 nonStrictResult = _nonStrictResult; 32 shouldBe("eval(stringLiteral)", "nonStrictResult"); 33 34 stringLiteral = '"use strict"; ' + stringLiteral; 35 if (_strictResult) { 36 strictResult = _strictResult; 37 shouldBe("eval(stringLiteral)", "strictResult"); 38 } else 39 shouldThrow("eval(stringLiteral)"); 40} 41 42// Tests for single digit octal and decimal escapes. 43// In non-strict mode 0-7 are octal escapes, 8-9 are NonEscapeCharacters. 44// In strict mode only "\0" is permitted. 45test("\\0", "\x00", "\x00"); 46test("\\1", "\x01"); 47test("\\7", "\x07"); 48test("\\8", "8"); 49test("\\9", "9"); 50 51// Tests for multi-digit octal values outside strict mode; 52// Octal literals may be 1-3 digits long. In strict more all multi-digit sequences are illegal. 53test("\\00", "\x00"); 54test("\\000", "\x00"); 55test("\\0000", "\x000"); 56 57test("\\01", "\x01"); 58test("\\001", "\x01"); 59test("\\0001", "\x001"); 60 61test("\\10", "\x08"); 62test("\\100", "\x40"); 63test("\\1000", "\x400"); 64 65test("\\19", "\x019"); 66test("\\109", "\x089"); 67test("\\1009", "\x409"); 68 69test("\\99", "99"); 70