diff --git a/harness/sm/non262-JSON-shell.js b/harness/sm/non262-JSON-shell.js index 5cf8ebcd8c..c57f5f1556 100644 --- a/harness/sm/non262-JSON-shell.js +++ b/harness/sm/non262-JSON-shell.js @@ -1,114 +1,64 @@ /*--- -defines: [testJSON] +defines: [testJSON, testJSONSyntaxError] allow_unused: True ---*/ -function testJSON(str, expectSyntaxError) -{ + +function testJSON(str) { // Leading and trailing whitespace never affect parsing, so test the string // multiple times with and without whitespace around it as it's easy and can // potentially detect bugs. // Try the provided string - try - { + try { JSON.parse(str); - reportCompare(false, expectSyntaxError, - "string <" + str + "> " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON"); - } - catch (e) - { - if (!(e instanceof SyntaxError)) - { - reportCompare(true, false, - "parsing string <" + str + "> threw a non-SyntaxError " + - "exception: " + e); - } - else - { - reportCompare(true, expectSyntaxError, - "string <" + str + "> " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON, exception: " + e); - } + } catch (e) { + throw new Test262Error("string <" + str + "> should have parsed as JSON"); } // Now try the provided string with trailing whitespace - try - { + try { JSON.parse(str + " "); - reportCompare(false, expectSyntaxError, - "string <" + str + " > " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON"); - } - catch (e) - { - if (!(e instanceof SyntaxError)) - { - reportCompare(true, false, - "parsing string <" + str + " > threw a non-SyntaxError " + - "exception: " + e); - } - else - { - reportCompare(true, expectSyntaxError, - "string <" + str + " > " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON, exception: " + e); - } + } catch (e) { + throw new Test262Error("string <" + str + " > should have parsed as JSON"); } // Now try the provided string with leading whitespace - try - { + try { JSON.parse(" " + str); - reportCompare(false, expectSyntaxError, - "string < " + str + "> " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON"); - } - catch (e) - { - if (!(e instanceof SyntaxError)) - { - reportCompare(true, false, - "parsing string < " + str + "> threw a non-SyntaxError " + - "exception: " + e); - } - else - { - reportCompare(true, expectSyntaxError, - "string < " + str + "> " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON, exception: " + e); - } + } catch (e) { + throw new Test262Error("string < " + str + "> should have parsed as JSON"); } // Now try the provided string with whitespace surrounding it - try - { + try { JSON.parse(" " + str + " "); - reportCompare(false, expectSyntaxError, - "string < " + str + " > " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON"); - } - catch (e) - { - if (!(e instanceof SyntaxError)) - { - reportCompare(true, false, - "parsing string < " + str + " > threw a non-SyntaxError " + - "exception: " + e); - } - else - { - reportCompare(true, expectSyntaxError, - "string < " + str + " > " + - "should" + (expectSyntaxError ? "n't" : "") + " " + - "have parsed as JSON, exception: " + e); - } + } catch (e) { + throw new Test262Error("string < " + str + " > should have parsed as JSON"); } } + +function testJSONSyntaxError(str) { + // Leading and trailing whitespace never affect parsing, so test the string + // multiple times with and without whitespace around it as it's easy and can + // potentially detect bugs. + + // Try the provided string + assert.throws(SyntaxError, function() { + JSON.parse(str); + }, "string <" + str + "> shouldn't have parsed as JSON"); + + // Now try the provided string with trailing whitespace + assert.throws(SyntaxError, function() { + JSON.parse(str + " "); + }, "string <" + str + " > shouldn't have parsed as JSON"); + + // Now try the provided string with leading whitespace + assert.throws(SyntaxError, function() { + JSON.parse(" " + str); + }, "string < " + str + "> shouldn't have parsed as JSON"); + + // Now try the provided string with whitespace surrounding it + assert.throws(SyntaxError, function() { + JSON.parse(" " + str + " "); + }, "string < " + str + " > shouldn't have parsed as JSON"); +} diff --git a/test/staging/sm/JSON/parse-number-syntax.js b/test/staging/sm/JSON/parse-number-syntax.js index 977a750b0d..87efc763c9 100644 --- a/test/staging/sm/JSON/parse-number-syntax.js +++ b/test/staging/sm/JSON/parse-number-syntax.js @@ -4,36 +4,31 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | pending esid: pending ---*/ -testJSON('-', true); -testJSON('+', true); -testJSON('-f', true); -testJSON('+f', true); -testJSON('00', true); -testJSON('01', true); -testJSON('1.', true); -testJSON('1.0e', true); -testJSON('1.0e+', true); -testJSON('1.0e-', true); -testJSON('1.0e+z', true); -testJSON('1.0e-z', true); -testJSON('1.0ee', true); -testJSON('1.e1', true); -testJSON('1.e+1', true); -testJSON('1.e-1', true); -testJSON('.', true); -testJSON('.1', true); -testJSON('.1e', true); -testJSON('.1e1', true); -testJSON('.1e+1', true); -testJSON('.1e-1', true); -/******************************************************************************/ - -print("Tests complete"); +testJSONSyntaxError('-'); +testJSONSyntaxError('+'); +testJSONSyntaxError('-f'); +testJSONSyntaxError('+f'); +testJSONSyntaxError('00'); +testJSONSyntaxError('01'); +testJSONSyntaxError('1.'); +testJSONSyntaxError('1.0e'); +testJSONSyntaxError('1.0e+'); +testJSONSyntaxError('1.0e-'); +testJSONSyntaxError('1.0e+z'); +testJSONSyntaxError('1.0e-z'); +testJSONSyntaxError('1.0ee'); +testJSONSyntaxError('1.e1'); +testJSONSyntaxError('1.e+1'); +testJSONSyntaxError('1.e-1'); +testJSONSyntaxError('.'); +testJSONSyntaxError('.1'); +testJSONSyntaxError('.1e'); +testJSONSyntaxError('.1e1'); +testJSONSyntaxError('.1e+1'); +testJSONSyntaxError('.1e-1'); diff --git a/test/staging/sm/JSON/parse-octal-syntax-error.js b/test/staging/sm/JSON/parse-octal-syntax-error.js index a8908b06d4..6db5a0f897 100644 --- a/test/staging/sm/JSON/parse-octal-syntax-error.js +++ b/test/staging/sm/JSON/parse-octal-syntax-error.js @@ -2,15 +2,10 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | pending esid: pending ---*/ -testJSON('{"Numbers cannot have leading zeroes": 013}', true); -/******************************************************************************/ - -print("Tests complete"); +testJSONSyntaxError('{"Numbers cannot have leading zeroes": 013}'); diff --git a/test/staging/sm/JSON/parse-syntax-errors-01.js b/test/staging/sm/JSON/parse-syntax-errors-01.js index c25f8e2e73..06dfc49c60 100644 --- a/test/staging/sm/JSON/parse-syntax-errors-01.js +++ b/test/staging/sm/JSON/parse-syntax-errors-01.js @@ -2,20 +2,15 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | pending esid: pending ---*/ -testJSON("{}...", true); -testJSON('{"foo": truBBBB}', true); -testJSON('{foo: truBBBB}', true); -testJSON('{"foo": undefined}', true); -testJSON('{"foo": ]', true); -testJSON('{"foo', true); -/******************************************************************************/ - -print("Tests complete"); +testJSONSyntaxError("{}..."); +testJSONSyntaxError('{"foo": truBBBB}'); +testJSONSyntaxError('{foo: truBBBB}'); +testJSONSyntaxError('{"foo": undefined}'); +testJSONSyntaxError('{"foo": ]'); +testJSONSyntaxError('{"foo'); diff --git a/test/staging/sm/JSON/parse-syntax-errors-02.js b/test/staging/sm/JSON/parse-syntax-errors-02.js index 8ea1aa4a5d..6ab40121ce 100644 --- a/test/staging/sm/JSON/parse-syntax-errors-02.js +++ b/test/staging/sm/JSON/parse-syntax-errors-02.js @@ -2,50 +2,45 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | pending esid: pending ---*/ -testJSON('"Unterminated string literal', true); -testJSON('["Unclosed array"', true); -testJSON('{unquoted_key: "keys must be quoted"}', true); -testJSON('["extra comma",]', true); -testJSON('["double extra comma",,]', true); -testJSON('[ , "<-- missing value"]', true); -testJSON('["Comma after the close"],', true); -testJSON('["Extra close"]]', true); -testJSON('{"Extra comma": true,}', true); -testJSON('{"Extra value after close": true} "misplaced quoted value"', true); -testJSON('{"Illegal expression": 1 + 2}', true); -testJSON('{"Illegal invocation": alert()}', true); -testJSON('{"Numbers cannot be hex": 0x14}', true); -testJSON('["Illegal backslash escape: \\x15"]', true); -testJSON('[\\naked]', true); -testJSON('["Illegal backslash escape: \\017"]', true); -testJSON('{"Missing colon" null}', true); -testJSON('{"Double colon":: null}', true); -testJSON('{"Comma instead of colon", null}', true); -testJSON('["Colon instead of comma": false]', true); -testJSON('["Bad value", truth]', true); -testJSON("['single quote']", true); -testJSON('[" tab character in string "]', true); -testJSON('["tab\\ character\\ in\\ string\\ "]', true); -testJSON('["line\rbreak"]', true); -testJSON('["line\nbreak"]', true); -testJSON('["line\r\nbreak"]', true); -testJSON('["line\\\rbreak"]', true); -testJSON('["line\\\nbreak"]', true); -testJSON('["line\\\r\nbreak"]', true); -testJSON('[0e]', true); -testJSON('[0e+]', true); -testJSON('[0e+-1]', true); -testJSON('{"Comma instead of closing brace": true,', true); -testJSON('["mismatch"}', true); -testJSON('0{', true); -/******************************************************************************/ - -print("Tests complete"); +testJSONSyntaxError('"Unterminated string literal'); +testJSONSyntaxError('["Unclosed array"'); +testJSONSyntaxError('{unquoted_key: "keys must be quoted"}'); +testJSONSyntaxError('["extra comma",]'); +testJSONSyntaxError('["double extra comma",,]'); +testJSONSyntaxError('[ , "<-- missing value"]'); +testJSONSyntaxError('["Comma after the close"],'); +testJSONSyntaxError('["Extra close"]]'); +testJSONSyntaxError('{"Extra comma": true,}'); +testJSONSyntaxError('{"Extra value after close": true} "misplaced quoted value"'); +testJSONSyntaxError('{"Illegal expression": 1 + 2}'); +testJSONSyntaxError('{"Illegal invocation": alert()}'); +testJSONSyntaxError('{"Numbers cannot be hex": 0x14}'); +testJSONSyntaxError('["Illegal backslash escape: \\x15"]'); +testJSONSyntaxError('[\\naked]'); +testJSONSyntaxError('["Illegal backslash escape: \\017"]'); +testJSONSyntaxError('{"Missing colon" null}'); +testJSONSyntaxError('{"Double colon":: null}'); +testJSONSyntaxError('{"Comma instead of colon", null}'); +testJSONSyntaxError('["Colon instead of comma": false]'); +testJSONSyntaxError('["Bad value", truth]'); +testJSONSyntaxError("['single quote']"); +testJSONSyntaxError('[" tab character in string "]'); +testJSONSyntaxError('["tab\\ character\\ in\\ string\\ "]'); +testJSONSyntaxError('["line\rbreak"]'); +testJSONSyntaxError('["line\nbreak"]'); +testJSONSyntaxError('["line\r\nbreak"]'); +testJSONSyntaxError('["line\\\rbreak"]'); +testJSONSyntaxError('["line\\\nbreak"]'); +testJSONSyntaxError('["line\\\r\nbreak"]'); +testJSONSyntaxError('[0e]'); +testJSONSyntaxError('[0e+]'); +testJSONSyntaxError('[0e+-1]'); +testJSONSyntaxError('{"Comma instead of closing brace": true,'); +testJSONSyntaxError('["mismatch"}'); +testJSONSyntaxError('0{'); diff --git a/test/staging/sm/JSON/parse-syntax-errors-03.js b/test/staging/sm/JSON/parse-syntax-errors-03.js index 2872348641..0a96b5c488 100644 --- a/test/staging/sm/JSON/parse-syntax-errors-03.js +++ b/test/staging/sm/JSON/parse-syntax-errors-03.js @@ -4,59 +4,54 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | pending esid: pending ---*/ -testJSON('[', true); -testJSON('[1', true); -testJSON('[1,]', true); -testJSON('[1,{', true); -testJSON('[1,}', true); -testJSON('[1,{]', true); -testJSON('[1,}]', true); -testJSON('[1,{"', true); -testJSON('[1,}"', true); -testJSON('[1,{"\\', true); -testJSON('[1,}"\\', true); -testJSON('[1,"', true); -testJSON('[1,"\\', true); -testJSON('{', true); -testJSON('{1', true); -testJSON('{,', true); -testJSON('{"', true); -testJSON('{"\\', true); -testJSON('{"\\u', true); -testJSON('{"\\uG', true); -testJSON('{"\\u0', true); -testJSON('{"\\u01', true); -testJSON('{"\\u012', true); -testJSON('{"\\u0123', true); -testJSON('{"\\u0123"', true); -testJSON('{"a"', true); -testJSON('{"a"}', true); -testJSON('{"a":', true); -testJSON('{"a",}', true); -testJSON('{"a":}', true); -testJSON('{"a":,}', true); -testJSON('{"a":5,}', true); -testJSON('{"a":5,[', true); -testJSON('{"a":5,"', true); -testJSON('{"a":5,"', true); -testJSON('{"a":5,"\\', true); -testJSON("a[false ]".substring(1, 7) /* "[false" */, true); +testJSONSyntaxError('['); +testJSONSyntaxError('[1'); +testJSONSyntaxError('[1,]'); +testJSONSyntaxError('[1,{'); +testJSONSyntaxError('[1,}'); +testJSONSyntaxError('[1,{]'); +testJSONSyntaxError('[1,}]'); +testJSONSyntaxError('[1,{"'); +testJSONSyntaxError('[1,}"'); +testJSONSyntaxError('[1,{"\\'); +testJSONSyntaxError('[1,}"\\'); +testJSONSyntaxError('[1,"'); +testJSONSyntaxError('[1,"\\'); -testJSON('this', true); +testJSONSyntaxError('{'); +testJSONSyntaxError('{1'); +testJSONSyntaxError('{,'); +testJSONSyntaxError('{"'); +testJSONSyntaxError('{"\\'); +testJSONSyntaxError('{"\\u'); +testJSONSyntaxError('{"\\uG'); +testJSONSyntaxError('{"\\u0'); +testJSONSyntaxError('{"\\u01'); +testJSONSyntaxError('{"\\u012'); +testJSONSyntaxError('{"\\u0123'); +testJSONSyntaxError('{"\\u0123"'); +testJSONSyntaxError('{"a"'); +testJSONSyntaxError('{"a"}'); +testJSONSyntaxError('{"a":'); +testJSONSyntaxError('{"a",}'); +testJSONSyntaxError('{"a":}'); +testJSONSyntaxError('{"a":,}'); +testJSONSyntaxError('{"a":5,}'); +testJSONSyntaxError('{"a":5,['); +testJSONSyntaxError('{"a":5,"'); +testJSONSyntaxError('{"a":5,"'); +testJSONSyntaxError('{"a":5,"\\'); +testJSONSyntaxError("a[false ]".substring(1, 7)); -testJSON('[1,{}]', false); -testJSON('{}', false); -testJSON('{"a":5}', false); -testJSON('{"\\u0123":5}', false); +testJSONSyntaxError('this'); -/******************************************************************************/ - -print("Tests complete"); +testJSON('[1,{}]'); +testJSON('{}'); +testJSON('{"a":5}'); +testJSON('{"\\u0123":5}'); diff --git a/test/staging/sm/JSON/small-codepoints.js b/test/staging/sm/JSON/small-codepoints.js index 8578a38379..2bc75a537b 100644 --- a/test/staging/sm/JSON/small-codepoints.js +++ b/test/staging/sm/JSON/small-codepoints.js @@ -4,23 +4,11 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | - pending + JSON.parse should reject U+0000 through U+001F esid: pending ---*/ -var gTestfile = 'small-codepoints.js'; -//----------------------------------------------------------------------------- -var BUGNUMBER = 554079; -var summary = 'JSON.parse should reject U+0000 through U+001F'; - -print(BUGNUMBER + ": " + summary); - -/************** - * BEGIN TEST * - **************/ for (var i = 0; i <= 0x1F; i++) - testJSON('["a' + String.fromCharCode(i) + 'c"]', true); + testJSONSyntaxError('["a' + String.fromCharCode(i) + 'c"]'); diff --git a/test/staging/sm/JSON/trailing-comma.js b/test/staging/sm/JSON/trailing-comma.js index c0543f1d32..8ea72d5f6e 100644 --- a/test/staging/sm/JSON/trailing-comma.js +++ b/test/staging/sm/JSON/trailing-comma.js @@ -4,39 +4,27 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-JSON-shell.js] -flags: - - noStrict +includes: [sm/non262-JSON-shell.js] description: | - pending + 'JSON.parse should reject {"a" : "b",} or [1,] esid: pending ---*/ -var gTestfile = 'trailing-comma.js'; -//----------------------------------------------------------------------------- -var BUGNUMBER = 564621; -var summary = 'JSON.parse should reject {"a" : "b",} or [1,]'; -print(BUGNUMBER + ": " + summary); +testJSON('[]'); +testJSON('[1]'); +testJSON('["a"]'); +testJSON('{}'); +testJSON('{"a":1}'); +testJSON('{"a":"b"}'); +testJSON('{"a":true}'); +testJSON('[{}]'); -/************** - * BEGIN TEST * - **************/ - -testJSON('[]', false); -testJSON('[1]', false); -testJSON('["a"]', false); -testJSON('{}', false); -testJSON('{"a":1}', false); -testJSON('{"a":"b"}', false); -testJSON('{"a":true}', false); -testJSON('[{}]', false); - -testJSON('[1,]', true); -testJSON('["a",]', true); -testJSON('{,}', true); -testJSON('{"a":1,}', true); -testJSON('{"a":"b",}', true); -testJSON('{"a":true,}', true); -testJSON('[{,}]', true); -testJSON('[[1,]]', true); -testJSON('[{"a":"b",}]', true); +testJSONSyntaxError('[1,]'); +testJSONSyntaxError('["a",]'); +testJSONSyntaxError('{,}'); +testJSONSyntaxError('{"a":1,}'); +testJSONSyntaxError('{"a":"b",}'); +testJSONSyntaxError('{"a":true,}'); +testJSONSyntaxError('[{,}]'); +testJSONSyntaxError('[[1,]]'); +testJSONSyntaxError('[{"a":"b",}]');