diff --git a/testcases/test-lex-line-continuation.js b/testcases/test-lex-line-continuation.js new file mode 100644 index 00000000..4381f3b6 --- /dev/null +++ b/testcases/test-lex-line-continuation.js @@ -0,0 +1,19 @@ + +/*=== +"This is a \ +line continuation." +This is a line continuation. +===*/ + +/* Line continuation inside a string. */ + +var str; + +try { + str = '"This is a \\\nline continuation."'; + print(str); + print(eval(str)); +} catch (e) { + print(e.name); +} + diff --git a/testcases/test-lex-unterminated-hex-uni-escape.js b/testcases/test-lex-unterminated-hex-uni-escape.js new file mode 100644 index 00000000..555e81f8 --- /dev/null +++ b/testcases/test-lex-unterminated-hex-uni-escape.js @@ -0,0 +1,80 @@ +/*=== +\u +1 u +\u1 +2 u1 +\u12 +3 u12 +\u123 +4 u123 +\u123G +5 u123G +\x +1 x +\x1 +2 x1 +\x1G +3 x1G +===*/ + +/* Unterminated hex or unicode escapes should apparently (?) be parsed with + * the longest match principle at least inside string literals. + * + * In other words, if the string ends or the escape is otherwise invalid, + * the escape characters should be parsed as itself: "\uX" -> "uX". + * + * Both V8 and Rhino parse these without a SyntaxError. + */ + +function testString(x) { + var t; + + print(x); + var t = eval('"' + x + '"'); + print(t.length, t); +} + +function testStrings() { + var strings = [ + '\\u', + '\\u1', + '\\u12', + '\\u123', + '\\u123G', + '\\x', + '\\x1', + '\\x1G', + ]; + var i; + + for (i = 0; i < strings.length; i++) { + try { + testString(strings[i]); + } catch (e) { + print(e); + } + } +} + + +try { + testStrings(); +} catch (e) { + print(e.name); +} + +/*=== +SyntaxError +===*/ + +/* However, an unterminated unicode escape outside a string literal + * won't be parsed by V8 or Rhino if it is broken. + */ + +try { + // if "\u" parsed as "u", same as assignemtn: u123 = 1 + print(eval('\\u123 = 1;')); +} catch (e) { + print(e.name); +} +