diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_2 | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_2')
192 files changed, 10992 insertions, 0 deletions
diff --git a/js/src/tests/ecma_2/Exceptions/boolean-001.js b/js/src/tests/ecma_2/Exceptions/boolean-001.js new file mode 100644 index 000000000..d2cea72b2 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/boolean-001.js @@ -0,0 +1,47 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: boolean-001.js + Description: Corresponds to ecma/Boolean/15.6.4.2-4-n.js + + The toString function is not generic; it generates + a runtime error if its this value is not a Boolean + object. Therefore it cannot be transferred to other + kinds of objects for use as a method. + + Author: christine@netscape.com + Date: june 27, 1997 +*/ +var SECTION = "boolean-001.js"; +var VERSION = "JS1_4"; +var TITLE = "Boolean.prototype.toString()"; +startTest(); +writeHeaderToLog( SECTION +" "+ TITLE ); + +var exception = "No exception thrown"; +var result = "Failed"; + +var TO_STRING = Boolean.prototype.toString; + +try { + var s = new String("Not a Boolean"); + s.toString = TO_STRING; + s.toString(); +} catch ( e ) { + result = "Passed!"; + exception = e.toString(); +} + +new TestCase( + SECTION, + "Assigning Boolean.prototype.toString to a String object "+ + "(threw " +exception +")", + "Passed!", + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/boolean-002.js b/js/src/tests/ecma_2/Exceptions/boolean-002.js new file mode 100644 index 000000000..8dd55ed6b --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/boolean-002.js @@ -0,0 +1,51 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: boolean-001.js + Description: Corresponds to ecma/Boolean/15.6.4.3-4-n.js + + 15.6.4.3 Boolean.prototype.valueOf() + Returns this boolean value. + + The valueOf function is not generic; it generates + a runtime error if its this value is not a Boolean + object. Therefore it cannot be transferred to other + kinds of objects for use as a method. + + Author: christine@netscape.com + Date: 09 september 1998 +*/ +var SECTION = "boolean-002.js"; +var VERSION = "JS1_4"; +var TITLE = "Boolean.prototype.valueOf()"; +startTest(); +writeHeaderToLog( SECTION +" "+ TITLE ); + + +var exception = "No exception thrown"; +var result = "Failed"; + +var VALUE_OF = Boolean.prototype.valueOf; + +try { + var s = new String("Not a Boolean"); + s.valueOf = VALUE_0F; + s.valueOf(); +} catch ( e ) { + result = "Passed!"; + exception = e.toString(); +} + +new TestCase( + SECTION, + "Assigning Boolean.prototype.valueOf to a String object "+ + "(threw " +exception +")", + "Passed!", + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/browser.js b/js/src/tests/ecma_2/Exceptions/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/browser.js diff --git a/js/src/tests/ecma_2/Exceptions/date-002.js b/js/src/tests/ecma_2/Exceptions/date-002.js new file mode 100644 index 000000000..0f379b541 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/date-002.js @@ -0,0 +1,54 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: date-002.js + Corresponds To: 15.9.5.23-3-n.js + ECMA Section: 15.9.5.23 + Description: Date.prototype.setTime + + 1. If the this value is not a Date object, generate a runtime error. + 2. Call ToNumber(time). + 3. Call TimeClip(Result(1)). + 4. Set the [[Value]] property of the this value to Result(2). + 5. Return the value of the [[Value]] property of the this value. + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "date-002"; +var VERSION = "JS1_4"; +var TITLE = "Date.prototype.setTime()"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var MYDATE = new MyDate(); + result = MYDATE.setTime(0); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "MYDATE = new MyDate(); MYDATE.setTime(0)" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyDate(value) { + this.value = value; + this.setTime = Date.prototype.setTime; + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/date-003.js b/js/src/tests/ecma_2/Exceptions/date-003.js new file mode 100644 index 000000000..f8f48c699 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/date-003.js @@ -0,0 +1,56 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: date-003.js + Corresponds To 15.9.5.3-1.js + ECMA Section: 15.9.5.3-1 Date.prototype.valueOf + Description: + + The valueOf function returns a number, which is this time value. + + The valueOf function is not generic; it generates a runtime error if + its this value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "date-003"; +var VERSION = "JS1_4"; +var TITLE = "Date.prototype.valueOf"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var OBJ = new MyObject( new Date(0) ); + result = OBJ.valueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "OBJ = new MyObject( new Date(0)); OBJ.valueOf()" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyObject( value ) { + this.value = value; + this.valueOf = Date.prototype.valueOf; +// The following line causes an infinte loop +// this.toString = new Function( "return this+\"\";"); + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/date-004.js b/js/src/tests/ecma_2/Exceptions/date-004.js new file mode 100644 index 000000000..fd8733cbd --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/date-004.js @@ -0,0 +1,50 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: date-004.js + Corresponds To: 15.9.5.4-2-n.js + ECMA Section: 15.9.5.4-1 Date.prototype.getTime + Description: + + 1. If the this value is not an object whose [[Class]] property is "Date", + generate a runtime error. + 2. Return this time value. + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "date-004"; +var VERSION = "JS1_4"; +var TITLE = "Date.prototype.getTime"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var MYDATE = new MyDate(); + result = MYDATE.getTime(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "MYDATE = new MyDate(); MYDATE.getTime()" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyDate( value ) { + this.value = value; + this.getTime = Date.prototype.getTime; +} diff --git a/js/src/tests/ecma_2/Exceptions/exception-001.js b/js/src/tests/ecma_2/Exceptions/exception-001.js new file mode 100644 index 000000000..987ba0af8 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-001.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-001 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * Call error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-001"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: CallError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +Call_1(); + +test(); + +function Call_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + Math(); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "Math() [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-002.js b/js/src/tests/ecma_2/Exceptions/exception-002.js new file mode 100644 index 000000000..74ce79a96 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-002.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-002 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * Construct error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-002"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: ConstructError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +Construct_1(); + +test(); + +function Construct_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = new Math(); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "new Math() [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-003.js b/js/src/tests/ecma_2/Exceptions/exception-003.js new file mode 100644 index 000000000..7bc02a627 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-003.js @@ -0,0 +1,49 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-003 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * Target error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-003"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: TargetError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +Target_1(); + +test(); + +function Target_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + string = new String("hi"); + string.toString = Boolean.prototype.toString; + string.toString(); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "string = new String(\"hi\");"+ + "string.toString = Boolean.prototype.toString" + + "string.toString() [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-004.js b/js/src/tests/ecma_2/Exceptions/exception-004.js new file mode 100644 index 000000000..41b7ac3aa --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-004.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-004 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * ToObject error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-004"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: ToObjectError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +ToObject_1(); + +test(); + +function ToObject_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = foo["bar"]; + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "foo[\"bar\"] [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-005.js b/js/src/tests/ecma_2/Exceptions/exception-005.js new file mode 100644 index 000000000..152aebe4b --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-005.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-005 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * ToObject error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-005"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: ToObjectError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +ToObject_1(); + +test(); + +function ToObject_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = foo["bar"]; + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "foo[\"bar\"] [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-006.js b/js/src/tests/ecma_2/Exceptions/exception-006.js new file mode 100644 index 000000000..cf9df729c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-006.js @@ -0,0 +1,56 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-006 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * ToPrimitive error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-006"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: TypeError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +ToPrimitive_1(); + +test(); + + +/** + * Getting the [[DefaultValue]] of any instances of MyObject + * should result in a runtime error in ToPrimitive. + */ + +function MyObject() { + this.toString = void 0; + this.valueOf = void 0; +} + +function ToPrimitive_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = new MyObject() + new MyObject(); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "new MyObject() + new MyObject() [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-007.js b/js/src/tests/ecma_2/Exceptions/exception-007.js new file mode 100644 index 000000000..bae0027b5 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-007.js @@ -0,0 +1,57 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-007 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * DefaultValue error. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-007"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: TypeError"; +var BUGNUMBER="318250"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DefaultValue_1(); + +test(); + + +/** + * Getting the [[DefaultValue]] of any instances of MyObject + * should result in a runtime error in ToPrimitive. + */ + +function MyObject() { + this.toString = void 0; + this.valueOf = new Object(); +} + +function DefaultValue_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = new MyObject() + new MyObject(); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "new MyObject() + new MyObject() [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} + diff --git a/js/src/tests/ecma_2/Exceptions/exception-008.js b/js/src/tests/ecma_2/Exceptions/exception-008.js new file mode 100644 index 000000000..f7efa9fb4 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-008.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-008 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * SyntaxError. + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-008"; +var VERSION = "js1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: SyntaxError"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +Syntax_1(); + +test(); + +function Syntax_1() { + result = "failed: no exception thrown"; + exception = null; + + try { + result = eval("continue;"); + } catch ( e ) { + result = "passed: threw exception", + exception = e.toString(); + } finally { + new TestCase( + SECTION, + "eval(\"continue\") [ exception is " + exception +" ]", + "passed: threw exception", + result ); + } +} diff --git a/js/src/tests/ecma_2/Exceptions/exception-009.js b/js/src/tests/ecma_2/Exceptions/exception-009.js new file mode 100644 index 000000000..1229bf561 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-009.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: exception-009 + * ECMA Section: + * Description: Tests for JavaScript Standard Exceptions + * + * Regression test for nested try blocks. + * + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=312964 + * + * Author: christine@netscape.com + * Date: 31 August 1998 + */ +var SECTION = "exception-009"; +var VERSION = "JS1_4"; +var TITLE = "Tests for JavaScript Standard Exceptions: SyntaxError"; +var BUGNUMBER= "312964"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +try { + expect = "passed: no exception thrown"; + result = expect; + Nested_1(); +} catch ( e ) { + result = "failed: threw " + e; +} finally { + new TestCase( + SECTION, + "nested try", + expect, + result ); +} + + +test(); + +function Nested_1() { + try { + try { + } catch (a) { + } finally { + } + } catch (b) { + } finally { + } +} diff --git a/js/src/tests/ecma_2/Exceptions/exception-010-n.js b/js/src/tests/ecma_2/Exceptions/exception-010-n.js new file mode 100644 index 000000000..46fe72fdd --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-010-n.js @@ -0,0 +1,25 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var SECTION = "exception-010"; +var VERSION = "ECMA_2"; +startTest(); +var TITLE = "Don't Crash throwing null"; + +writeHeaderToLog( SECTION + " "+ TITLE); +print("Null throw test."); +print("BUGNUMBER: 21799"); + +DESCRIPTION = "throw null"; +EXPECTED = "error"; + +new TestCase( SECTION, "throw null", "error", eval("throw null" )); + +test(); + +print("FAILED!: Should have exited with uncaught exception."); + + diff --git a/js/src/tests/ecma_2/Exceptions/exception-011-n.js b/js/src/tests/ecma_2/Exceptions/exception-011-n.js new file mode 100644 index 000000000..17f19723d --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/exception-011-n.js @@ -0,0 +1,26 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var SECTION = "exception-011"; +var VERSION = "ECMA_2"; +startTest(); +var TITLE = "Don't Crash throwing undefined"; + +writeHeaderToLog( SECTION + " "+ TITLE); + +print("Undefined throw test."); + +DESCRIPTION = "throw undefined"; +EXPECTED = "error"; + +new TestCase( SECTION, "throw undefined", "error", eval("throw (void 0)") ); + +test(); + +print("FAILED!: Should have exited with uncaught exception."); + + + diff --git a/js/src/tests/ecma_2/Exceptions/expression-001.js b/js/src/tests/ecma_2/Exceptions/expression-001.js new file mode 100644 index 000000000..90b44839f --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-001.js @@ -0,0 +1,50 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-001.js + Corresponds to: ecma/Expressions/11.12-2-n.js + ECMA Section: 11.12 + Description: + + The grammar for a ConditionalExpression in ECMAScript is a little bit + different from that in C and Java, which each allow the second + subexpression to be an Expression but restrict the third expression to + be a ConditionalExpression. The motivation for this difference in + ECMAScript is to allow an assignment expression to be governed by either + arm of a conditional and to eliminate the confusing and fairly useless + case of a comma expression as the center expression. + + Author: christine@netscape.com + Date: 09 september 1998 +*/ +var SECTION = "expression-001"; +var VERSION = "JS1_4"; +var TITLE = "Conditional operator ( ? : )" + startTest(); +writeHeaderToLog( SECTION + " " + TITLE ); + +// the following expression should be an error in JS. + +var result = "Failed" + var exception = "No exception was thrown"; + +try { + eval("var MY_VAR = true ? \"EXPR1\", \"EXPR2\" : \"EXPR3\""); +} catch ( e ) { + result = "Passed"; + exception = e.toString(); +} + +new TestCase( + SECTION, + "comma expression in a conditional statement "+ + "(threw "+ exception +")", + "Passed", + result ); + + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-002.js b/js/src/tests/ecma_2/Exceptions/expression-002.js new file mode 100644 index 000000000..0110f23b7 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-002.js @@ -0,0 +1,60 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expressions-002.js + Corresponds to: ecma/Expressions/11.2.1-3-n.js + ECMA Section: 11.2.1 Property Accessors + Description: + + Try to access properties of an object whose value is undefined. + + Author: christine@netscape.com + Date: 09 september 1998 +*/ +var SECTION = "expressions-002.js"; +var VERSION = "JS1_4"; +var TITLE = "Property Accessors"; +writeHeaderToLog( SECTION + " "+TITLE ); + +startTest(); + +// go through all Native Function objects, methods, and properties and get their typeof. + +var PROPERTY = new Array(); +var p = 0; + +// try to access properties of primitive types + +OBJECT = new Property( "undefined", void 0, "undefined", NaN ); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = OBJECT.value.valueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + + +new TestCase( + SECTION, + "Get the value of an object whose value is undefined "+ + "(threw " + exception +")", + expect, + result ); + +test(); + +function Property( object, value, string, number ) { + this.object = object; + this.string = String(value); + this.number = Number(value); + this.valueOf = value; +} diff --git a/js/src/tests/ecma_2/Exceptions/expression-003.js b/js/src/tests/ecma_2/Exceptions/expression-003.js new file mode 100644 index 000000000..ba5f9c076 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-003.js @@ -0,0 +1,55 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expressions-003.js + Corresponds to: ecma/Expressions/11.2.1-3-n.js + ECMA Section: 11.2.1 Property Accessors + Description: + + Try to access properties of an object whose value is undefined. + + Author: christine@netscape.com + Date: 09 september 1998 +*/ +var SECTION = "expressions-003.js"; +var VERSION = "JS1_4"; +var TITLE = "Property Accessors"; +writeHeaderToLog( SECTION + " "+TITLE ); + +startTest(); + +// try to access properties of primitive types + +OBJECT = new Property( "undefined", void 0, "undefined", NaN ); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = OBJECT.value.toString(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + + +new TestCase( + SECTION, + "Get the toString value of an object whose value is undefined "+ + "(threw " + exception +")", + expect, + result ); + +test(); + +function Property( object, value, string, number ) { + this.object = object; + this.string = String(value); + this.number = Number(value); + this.value = value; +} diff --git a/js/src/tests/ecma_2/Exceptions/expression-004.js b/js/src/tests/ecma_2/Exceptions/expression-004.js new file mode 100644 index 000000000..5bf19d9e5 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-004.js @@ -0,0 +1,49 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-004.js + Corresponds To: 11.2.1-4-n.js + ECMA Section: 11.2.1 Property Accessors + Description: + + Author: christine@netscape.com + Date: 09 september 1998 +*/ +var SECTION = "expression-004"; +var VERSION = "JS1_4"; +var TITLE = "Property Accessors"; +writeHeaderToLog( SECTION + " "+TITLE ); +startTest(); + +var OBJECT = new Property( "null", null, "null", 0 ); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = OBJECT.value.toString(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "Get the toString value of an object whose value is null "+ + "(threw " + exception +")", + expect, + result ); + +test(); + +function Property( object, value, string, number ) { + this.object = object; + this.string = String(value); + this.number = Number(value); + this.value = value; +} diff --git a/js/src/tests/ecma_2/Exceptions/expression-005.js b/js/src/tests/ecma_2/Exceptions/expression-005.js new file mode 100644 index 000000000..c1e76b7c6 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-005.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-005.js + Corresponds To: 11.2.2-10-n.js + ECMA Section: 11.2.2. The new operator + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ + +var SECTION = "expression-005"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var expect = "Passed"; +var exception = "No exception thrown"; + +try { + result = new Math(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "result= new Math() (threw " + exception + ")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-006.js b/js/src/tests/ecma_2/Exceptions/expression-006.js new file mode 100644 index 000000000..2ab13479a --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-006.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-006.js + Corresponds to: 11.2.2-1-n.js + ECMA Section: 11.2.2. The new operator + Description: + + http://scopus/bugsplat/show_bug.cgi?id=327765 + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-006.js"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; +var BUGNUMBER="327765"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var OBJECT = new Object(); + result = new OBJECT(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "OBJECT = new Object; result = new OBJECT()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-007.js b/js/src/tests/ecma_2/Exceptions/expression-007.js new file mode 100644 index 000000000..3e01e0d8c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-007.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-007.js + Corresponds To: 11.2.2-2-n.js + ECMA Section: 11.2.2. The new operator + Description: + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-007"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + UNDEFINED = void 0; + result = new UNDEFINED(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "UNDEFINED = void 0; result = new UNDEFINED()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-008.js b/js/src/tests/ecma_2/Exceptions/expression-008.js new file mode 100644 index 000000000..caf310195 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-008.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-008 + Corresponds To: 11.2.2-3-n.js + ECMA Section: 11.2.2. The new operator + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-008"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var NULL = null; +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new NULL(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "NULL = null; result = new NULL()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-009.js b/js/src/tests/ecma_2/Exceptions/expression-009.js new file mode 100644 index 000000000..9a997d7fb --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-009.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-009 + Corresponds to: ecma/Expressions/11.2.2-4-n.js + ECMA Section: 11.2.2. The new operator + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-009"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var STRING = ""; + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new STRING(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "STRING = ''; result = new STRING()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-010.js b/js/src/tests/ecma_2/Exceptions/expression-010.js new file mode 100644 index 000000000..f8ad983cc --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-010.js @@ -0,0 +1,43 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-010.js + Corresponds To: 11.2.2-5-n.js + ECMA Section: 11.2.2. The new operator + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-010"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var NUMBER = 0; + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new NUMBER(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "NUMBER=0, result = new NUMBER()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-011.js b/js/src/tests/ecma_2/Exceptions/expression-011.js new file mode 100644 index 000000000..8337b9b76 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-011.js @@ -0,0 +1,43 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-011.js + Corresponds To: ecma/Expressions/11.2.2-6-n.js + ECMA Section: 11.2.2. The new operator + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-011"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var BOOLEAN = true; + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var OBJECT = new BOOLEAN(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "BOOLEAN = true; result = new BOOLEAN()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-012.js b/js/src/tests/ecma_2/Exceptions/expression-012.js new file mode 100644 index 000000000..69e39ba47 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-012.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-012.js + Corresponds To: ecma/Expressions/11.2.2-6-n.js + ECMA Section: 11.2.2. The new operator + Description: + http://scopus/bugsplat/show_bug.cgi?id=327765 + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-012"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; +var BUGNUMBER= "327765"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var STRING = new String("hi"); +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new STRING(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "STRING = new String(\"hi\"); result = new STRING()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-013.js b/js/src/tests/ecma_2/Exceptions/expression-013.js new file mode 100644 index 000000000..f4986a5c0 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-013.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-013.js + Corresponds To: ecma/Expressions/11.2.2-8-n.js + ECMA Section: 11.2.2. The new operator + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-013"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; +var BUGNUMBER= "327765"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var NUMBER = new Number(1); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new NUMBER(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "NUMBER = new Number(1); result = new NUMBER()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-014.js b/js/src/tests/ecma_2/Exceptions/expression-014.js new file mode 100644 index 000000000..ac2dadaec --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-014.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-014.js + Corresponds To: ecma/Expressions/11.2.2-9-n.js + ECMA Section: 11.2.2. The new operator + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-014.js"; +var VERSION = "ECMA_1"; +var TITLE = "The new operator"; +var BUGNUMBER= "327765"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var BOOLEAN = new Boolean(); + + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new BOOLEAN(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "BOOLEAN = new Boolean(); result = new BOOLEAN()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/expression-015.js b/js/src/tests/ecma_2/Exceptions/expression-015.js new file mode 100644 index 000000000..4febd4c3c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-015.js @@ -0,0 +1,40 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-015.js + Corresponds To: ecma/Expressions/11.2.3-2-n.js + ECMA Section: 11.2.3. Function Calls + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-015"; +var VERSION = "JS1_4"; +var TITLE = "Function Calls"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("result = 3.valueOf();"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "3.valueOf()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-016.js b/js/src/tests/ecma_2/Exceptions/expression-016.js new file mode 100644 index 000000000..9d0bfcef4 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-016.js @@ -0,0 +1,40 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-016.js + Corresponds To: ecma/Expressions/11.2.3-3-n.js + ECMA Section: 11.2.3. Function Calls + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-016"; +var VERSION = "JS1_4"; +var TITLE = "Function Calls"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = (void 0).valueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "(void 0).valueOf()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-017.js b/js/src/tests/ecma_2/Exceptions/expression-017.js new file mode 100644 index 000000000..1e357ead7 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-017.js @@ -0,0 +1,40 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-07.js + Corresponds To: ecma/Expressions/11.2.3-4-n.js + ECMA Section: 11.2.3. Function Calls + Description: + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-017"; +var VERSION = "JS1_4"; +var TITLE = "Function Calls"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = nullvalueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "null.valueOf()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/expression-019.js b/js/src/tests/ecma_2/Exceptions/expression-019.js new file mode 100644 index 000000000..76c26bcae --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/expression-019.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: expression-019.js + Corresponds To: 11.2.2-7-n.js + ECMA Section: 11.2.2. The new operator + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "expression-019"; +var VERSION = "JS1_4"; +var TITLE = "The new operator"; +var BUGNUMBER= "327765"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var STRING = new String("hi"); + result = new STRING(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var STRING = new String(\"hi\"); result = new STRING();" + + " (threw " + exception + ")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/function-001.js b/js/src/tests/ecma_2/Exceptions/function-001.js new file mode 100644 index 000000000..ab8b9fa71 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/function-001.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: boolean-001.js + * Description: + * + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99232 + * + * eval("function f(){}function g(){}") at top level is an error for JS1.2 + * and above (missing ; between named function expressions), but declares f + * and g as functions below 1.2. + * + * Fails to produce error regardless of version: + * js> version(100) + * 120 + * js> eval("function f(){}function g(){}") + * js> version(120); + * 100 + * js> eval("function f(){}function g(){}") + * js> + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "function-001.js"; +var VERSION = "JS_12"; +var TITLE = "functions not separated by semicolons are errors in version 120 and higher"; +var BUGNUMBER="10278"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "pass"; +var exception = "no exception thrown"; + +try { + eval("function f(){}function g(){}"); +} catch ( e ) { + result = "fail"; + exception = e.toString(); +} + +new TestCase( + SECTION, + "eval(\"function f(){}function g(){}\") (threw "+exception, + "pass", + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/global-001.js b/js/src/tests/ecma_2/Exceptions/global-001.js new file mode 100644 index 000000000..228b110c8 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/global-001.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: global-001 + Corresponds To: ecma/GlobalObject/15.1-1-n.js + ECMA Section: The global object + Description: + + The global object does not have a [[Construct]] property; it is not + possible to use the global object as a constructor with the new operator. + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "global-001"; +var VERSION = "ECMA_1"; +var TITLE = "The Global Object"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = new this(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "result = new this()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/global-002.js b/js/src/tests/ecma_2/Exceptions/global-002.js new file mode 100644 index 000000000..1639a34bb --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/global-002.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: global-002 + Corresponds To: ecma/GlobalObject/15.1-2-n.js + ECMA Section: The global object + Description: + + The global object does not have a [[Construct]] property; it is not + possible to use the global object as a constructor with the new operator. + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "global-002"; +var VERSION = "JS1_4"; +var TITLE = "The Global Object"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = this(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "result = this()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-001.js b/js/src/tests/ecma_2/Exceptions/lexical-001.js new file mode 100644 index 000000000..3dbd61d99 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-001.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-001.js + CorrespondsTo: ecma/LexicalConventions/7.2.js + ECMA Section: 7.2 Line Terminators + Description: - readability + - separate tokens + - may occur between any two tokens + - cannot occur within any token, not even a string + - affect the process of automatic semicolon insertion. + + white space characters are: + unicode name formal name string representation + \u000A line feed <LF> \n + \u000D carriage return <CR> \r + + this test uses onerror to capture line numbers. because + we use on error, we can only have one test case per file. + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-001"; +var VERSION = "JS1_4"; +var TITLE = "Line Terminators"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = eval("\r\n\expect"); +} catch ( e ) { + exception = e.toString(); +} + +new TestCase( + SECTION, + "OBJECT = new Object; result = new OBJECT()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-002.js b/js/src/tests/ecma_2/Exceptions/lexical-002.js new file mode 100644 index 000000000..19eb30c0d --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-002.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-002.js + Corresponds To: ecma/LexicalConventions/7.2-3-n.js + ECMA Section: 7.2 Line Terminators + Description: - readability + - separate tokens + - may occur between any two tokens + - cannot occur within any token, not even a string + - affect the process of automatic semicolon insertion. + + white space characters are: + unicode name formal name string representation + \u000A line feed <LF> \n + \u000D carriage return <CR> \r + + this test uses onerror to capture line numbers. because + we use on error, we can only have one test case per file. + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-002"; +var VERSION = "JS1_4"; +var TITLE = "Line Terminators"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + result = eval("\r\n\expect"); +} catch ( e ) { + exception = e.toString(); +} + +new TestCase( + SECTION, + "result=eval(\"\r\nexpect\")" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-003.js b/js/src/tests/ecma_2/Exceptions/lexical-003.js new file mode 100644 index 000000000..46d60cb7f --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-003.js @@ -0,0 +1,43 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-003.js + Corresponds To: 7.3-13-n.js + ECMA Section: 7.3 Comments + Description: + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-003.js"; +var VERSION = "JS1_4"; +var TITLE = "Comments"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("/*\n/* nested comment */\n*/\n"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "/*/*nested comment*/ */" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-004.js b/js/src/tests/ecma_2/Exceptions/lexical-004.js new file mode 100644 index 000000000..853887db3 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-004.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-004.js + Corresponds To: ecma/LexicalExpressions/7.4.1-1-n.js + ECMA Section: 7.4.1 + + Description: + + Reserved words cannot be used as identifiers. + + ReservedWord :: + Keyword + FutureReservedWord + NullLiteral + BooleanLiteral + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-004"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var null = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var null = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-005.js b/js/src/tests/ecma_2/Exceptions/lexical-005.js new file mode 100644 index 000000000..2f3d3bdd8 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-005.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-005.js + Corresponds To: 7.4.1-2.js + ECMA Section: 7.4.1 + + Description: + + Reserved words cannot be used as identifiers. + + ReservedWord :: + Keyword + FutureReservedWord + NullLiteral + BooleanLiteral + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-005"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("true = false;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "true = false" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-006.js b/js/src/tests/ecma_2/Exceptions/lexical-006.js new file mode 100644 index 000000000..b37fe0d52 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-006.js @@ -0,0 +1,58 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-006.js + Corresponds To: 7.4.2-1.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-006"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("break = new Object();"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "break = new Object()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-007.js b/js/src/tests/ecma_2/Exceptions/lexical-007.js new file mode 100644 index 000000000..255a8b859 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-007.js @@ -0,0 +1,51 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-005.js + Corresponds To: 7.4.1-3-n.js + ECMA Section: 7.4.1 + + Description: + + Reserved words cannot be used as identifiers. + + ReservedWord :: + Keyword + FutureReservedWord + NullLiteral + BooleanLiteral + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-005"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("false = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "false = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-008.js b/js/src/tests/ecma_2/Exceptions/lexical-008.js new file mode 100644 index 000000000..b24b85875 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-008.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-008.js + Corresponds To: 7.4.3-1-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-008.js"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("case = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "case = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-009.js b/js/src/tests/ecma_2/Exceptions/lexical-009.js new file mode 100644 index 000000000..d5dc0ed44 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-009.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-009 + Corresponds To: 7.4.3-2-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-009"; +var VERSION = "ECMA_1"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("debugger = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "debugger = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-010.js b/js/src/tests/ecma_2/Exceptions/lexical-010.js new file mode 100644 index 000000000..7e7f8f9fb --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-010.js @@ -0,0 +1,52 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-010.js + Corresponds To: 7.4.3-3-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-010"; +var VERSION = "ECMA_1"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("export = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "export = true" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-011.js b/js/src/tests/ecma_2/Exceptions/lexical-011.js new file mode 100644 index 000000000..b67032842 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-011.js @@ -0,0 +1,62 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-011.js + Corresponds To: 7.4.3-4-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-011"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +print("This test requires option javascript.options.strict enabled"); + +if (!options().match(/strict/)) +{ + options('strict'); +} +if (!options().match(/werror/)) +{ + options('werror'); +} + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("super = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "super = true" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-012.js b/js/src/tests/ecma_2/Exceptions/lexical-012.js new file mode 100644 index 000000000..bed3322dd --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-012.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-012.js + Corresponds To: 7.4.3-5-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-012"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("catch = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "catch = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-013.js b/js/src/tests/ecma_2/Exceptions/lexical-013.js new file mode 100644 index 000000000..1fc0bf38a --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-013.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-013.js + Corresponds To: 7.4.3-6-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-013"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("default = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "default = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-014.js b/js/src/tests/ecma_2/Exceptions/lexical-014.js new file mode 100644 index 000000000..05f0c3cf9 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-014.js @@ -0,0 +1,62 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-014.js + Corresponds To: 7.4.3-7-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-014.js"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +print("This test requires option javascript.options.strict enabled"); + +if (!options().match(/strict/)) +{ + options('strict'); +} +if (!options().match(/werror/)) +{ + options('werror'); +} + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("extends = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "extends = true" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-015.js b/js/src/tests/ecma_2/Exceptions/lexical-015.js new file mode 100644 index 000000000..7d8c8e80b --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-015.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-015.js + Corresponds To: 7.4.3-8-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-015"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("switch = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "switch = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-016.js b/js/src/tests/ecma_2/Exceptions/lexical-016.js new file mode 100644 index 000000000..419af22c0 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-016.js @@ -0,0 +1,62 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-016 + Corresponds To: 7.4.3-9-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-016"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +print("This test requires option javascript.options.strict enabled"); + +if (!options().match(/strict/)) +{ + options('strict'); +} +if (!options().match(/werror/)) +{ + options('werror'); +} + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("class = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "class = true" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-017.js b/js/src/tests/ecma_2/Exceptions/lexical-017.js new file mode 100644 index 000000000..d7d33b4f0 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-017.js @@ -0,0 +1,54 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-017.js + Corresponds To: 7.4.3-10-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-017"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("do = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "do = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-018.js b/js/src/tests/ecma_2/Exceptions/lexical-018.js new file mode 100644 index 000000000..4d151e67b --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-018.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-018 + Corresponds To: 7.4.3-11-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-018"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("finally = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "finally = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-019.js b/js/src/tests/ecma_2/Exceptions/lexical-019.js new file mode 100644 index 000000000..0280b7710 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-019.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-019.js + Corresponds To: 7.4.3-12-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-019"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("throw = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "throw = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-020.js b/js/src/tests/ecma_2/Exceptions/lexical-020.js new file mode 100644 index 000000000..7be919181 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-020.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-020.js + Corresponds To 7.4.3-13-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-020"; +var VERSION = "JS1_4"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("const = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "const = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-021.js b/js/src/tests/ecma_2/Exceptions/lexical-021.js new file mode 100644 index 000000000..a3b4422cc --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-021.js @@ -0,0 +1,62 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-021.js + Corresponds To: 7.4.3-14-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-021.js"; +var VERSION = "ECMA_1"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +print("This test requires option javascript.options.strict enabled"); + +if (!options().match(/strict/)) +{ + options('strict'); +} +if (!options().match(/werror/)) +{ + options('werror'); +} + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("enum = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "enum = true" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-022.js b/js/src/tests/ecma_2/Exceptions/lexical-022.js new file mode 100644 index 000000000..d8671a453 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-022.js @@ -0,0 +1,54 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-022 + Corresponds To 7.4.3-15-n.js + ECMA Section: 7.4.3 + + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-022.js"; +var VERSION = "ECMA_1"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("import = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "import = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-023.js b/js/src/tests/ecma_2/Exceptions/lexical-023.js new file mode 100644 index 000000000..d5df7ce7d --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-023.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-023.js + Corresponds To: 7.4.3-16-n.js + ECMA Section: 7.4.3 + Description: + The following words are used as keywords in proposed extensions and are + therefore reserved to allow for the possibility of future adoption of + those extensions. + + FutureReservedWord :: one of + case debugger export super + catch default extends switch + class do finally throw + const enum import try + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "lexical-023.js"; +var VERSION = "ECMA_1"; +var TITLE = "Future Reserved Words"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("try = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "try = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-024.js b/js/src/tests/ecma_2/Exceptions/lexical-024.js new file mode 100644 index 000000000..be1c3a7b9 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-024.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-024 + Corresponds To: 7.4.2-1-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-024"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var break;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var break" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-025.js b/js/src/tests/ecma_2/Exceptions/lexical-025.js new file mode 100644 index 000000000..0dbb3ac63 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-025.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-025.js + Corresponds To 7.4.2-2-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-025"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var for;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var for" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-026.js b/js/src/tests/ecma_2/Exceptions/lexical-026.js new file mode 100644 index 000000000..2711de089 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-026.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-026.js + Corresponds To: 7.4.2-3-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-026"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var new;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var new" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-027.js b/js/src/tests/ecma_2/Exceptions/lexical-027.js new file mode 100644 index 000000000..0d8ddf079 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-027.js @@ -0,0 +1,61 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-027.js + Corresponds To: 7.4.2-4-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + var + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-027"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var var;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var var" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-028.js b/js/src/tests/ecma_2/Exceptions/lexical-028.js new file mode 100644 index 000000000..2b75204c7 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-028.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-028.js + Corresponds To: 7.4.2-5-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-028"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var continue=true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var continue=true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-029.js b/js/src/tests/ecma_2/Exceptions/lexical-029.js new file mode 100644 index 000000000..f559b5d05 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-029.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-029.js + Corresponds To: 7.4.2-6.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-029"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var function = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var function = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-030.js b/js/src/tests/ecma_2/Exceptions/lexical-030.js new file mode 100644 index 000000000..f5fc09620 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-030.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-030.js + Corresponds To: 7.4.2-7-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-030"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var return = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var return = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-031.js b/js/src/tests/ecma_2/Exceptions/lexical-031.js new file mode 100644 index 000000000..53f0c399c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-031.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-031.js + Corresponds To: 7.4.2-8-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-031"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var return;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var return" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-032.js b/js/src/tests/ecma_2/Exceptions/lexical-032.js new file mode 100644 index 000000000..a4196950b --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-032.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-032.js + Corresponds To: 7.4.2-9-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-032"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("delete = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "delete = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-033.js b/js/src/tests/ecma_2/Exceptions/lexical-033.js new file mode 100644 index 000000000..f36daaff8 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-033.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-033.js + Corresponds To: 7.4.2-10.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-033"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("if = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "if = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-034.js b/js/src/tests/ecma_2/Exceptions/lexical-034.js new file mode 100644 index 000000000..b160e3d03 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-034.js @@ -0,0 +1,58 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: 7.4.2-11-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-034"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("this = true"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "this = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-035.js b/js/src/tests/ecma_2/Exceptions/lexical-035.js new file mode 100644 index 000000000..c061c60ab --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-035.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-035.js + Correpsonds To: 7.4.2-12-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-035"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var while"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var while" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-036.js b/js/src/tests/ecma_2/Exceptions/lexical-036.js new file mode 100644 index 000000000..6b0c3e9ed --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-036.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-036.js + Corresponds To: 7.4.2-13-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-036"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("else = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "else = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-037.js b/js/src/tests/ecma_2/Exceptions/lexical-037.js new file mode 100644 index 000000000..d42c13170 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-037.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-037.js + Corresponds To: 7.4.2-14-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-028"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var in;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var in" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-038.js b/js/src/tests/ecma_2/Exceptions/lexical-038.js new file mode 100644 index 000000000..abcb85790 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-038.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-038.js + Corresponds To: 7.4.2-15-n.js + ECMA Section: 7.4.2 + + Description: + The following tokens are ECMAScript keywords and may not be used as + identifiers in ECMAScript programs. + + Syntax + + Keyword :: one of + break for new var + continue function return void + delete if this while + else in typeof with + + This test verifies that the keyword cannot be used as an identifier. + Functioinal tests of the keyword may be found in the section corresponding + to the function of the keyword. + + Author: christine@netscape.com + Date: 12 november 1997 + +*/ +var SECTION = "lexical-038"; +var VERSION = "JS1_4"; +var TITLE = "Keywords"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("typeof = true;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "typeof = true" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-039.js b/js/src/tests/ecma_2/Exceptions/lexical-039.js new file mode 100644 index 000000000..01e4407b3 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-039.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-039 + Corresponds To: 7.5-2-n.js + ECMA Section: 7.5 Identifiers + Description: Identifiers are of unlimited length + - can contain letters, a decimal digit, _, or $ + - the first character cannot be a decimal digit + - identifiers are case sensitive + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-039"; +var VERSION = "JS1_4"; +var TITLE = "Identifiers"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var 0abc;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var 0abc" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-040.js b/js/src/tests/ecma_2/Exceptions/lexical-040.js new file mode 100644 index 000000000..346345579 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-040.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-040.js + Corresponds To: 7.5-2.js + ECMA Section: 7.5 Identifiers + Description: Identifiers are of unlimited length + - can contain letters, a decimal digit, _, or $ + - the first character cannot be a decimal digit + - identifiers are case sensitive + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-040"; +var VERSION = "JS1_4"; +var TITLE = "Identifiers"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var 1abc;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var 1abc" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-041.js b/js/src/tests/ecma_2/Exceptions/lexical-041.js new file mode 100644 index 000000000..9687c7adc --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-041.js @@ -0,0 +1,48 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-041.js + Corresponds To: 7.5-8-n.js + ECMA Section: 7.5 Identifiers + Description: Identifiers are of unlimited length + - can contain letters, a decimal digit, _, or $ + - the first character cannot be a decimal digit + - identifiers are case sensitive + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-041"; +var VERSION = "ECMA_1"; +var TITLE = "Identifiers"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var @abc;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var @abc" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-042.js b/js/src/tests/ecma_2/Exceptions/lexical-042.js new file mode 100644 index 000000000..0defe9708 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-042.js @@ -0,0 +1,49 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-042.js + Corresponds To: 7.5-9-n.js + ECMA Section: 7.5 Identifiers + Description: Identifiers are of unlimited length + - can contain letters, a decimal digit, _, or $ + - the first character cannot be a decimal digit + - identifiers are case sensitive + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "lexical-042"; +var VERSION = "JS1_4"; +var TITLE = "Identifiers"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("var 123;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "var 123" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-047.js b/js/src/tests/ecma_2/Exceptions/lexical-047.js new file mode 100644 index 000000000..7fa084bd3 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-047.js @@ -0,0 +1,50 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-047.js + Corresponds To: 7.8.1-7-n.js + ECMA Section: 7.8.1 + Description: + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-047"; +var VERSION = "JS1_4"; +var TITLE = "for loops"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var counter = 0; + eval("for ( counter = 0\n" + + "counter <= 1\n" + + "counter++ )\n" + + "{\n" + + "result += \": got to inner loop\";\n" + + "}\n"); + +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "line breaks within a for expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-048.js b/js/src/tests/ecma_2/Exceptions/lexical-048.js new file mode 100644 index 000000000..788c3240e --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-048.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-048.js + Corresponds To: 7.8.1-1.js + ECMA Section: 7.8.1 Rules of Automatic Semicolon Insertion + Description: + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-048"; +var VERSION = "JS1_4"; +var TITLE = "The Rules of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var counter = 0; + eval( "for ( counter = 0;\ncounter <= 1\ncounter++ ) {\nresult += \": got inside for loop\")"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "line breaks within a for expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-049.js b/js/src/tests/ecma_2/Exceptions/lexical-049.js new file mode 100644 index 000000000..ea2483fd8 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-049.js @@ -0,0 +1,49 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-049 + Corresponds To: 7.8.1-1.js + ECMA Section: 7.8.1 Rules of Automatic Semicolon Insertioin + Description: + Author: christine@netscape.com + Date: 15 september 1997 +*/ +var SECTION = "lexical-049"; +var VERSION = "JS1_4"; +var TITLE = "The Rules of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var counter = 0; + eval("for ( counter = 0\n" + + "counter <= 1;\n" + + "counter++ )\n" + + "{\n" + + "result += \": got inside for loop\";\n" + + "}\n"); + +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "line breaks within a for expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-050.js b/js/src/tests/ecma_2/Exceptions/lexical-050.js new file mode 100644 index 000000000..d0079468a --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-050.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-050.js + Corresponds to: 7.8.2-1-n.js + ECMA Section: 7.8.2 Examples of Automatic Semicolon Insertion + Description: compare some specific examples of the automatic + insertion rules in the EMCA specification. + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-050"; +var VERSION = "JS1_4"; +var TITLE = "Examples of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("{ 1 2 } 3"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "{ 1 2 } 3" + + " (threw " + exception +")", + expect, + result ); + +test(); + + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-051.js b/js/src/tests/ecma_2/Exceptions/lexical-051.js new file mode 100644 index 000000000..1fec695d6 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-051.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-051.js + Corresponds to: 7.8.2-3-n.js + ECMA Section: 7.8.2 Examples of Automatic Semicolon Insertion + Description: compare some specific examples of the automatic + insertion rules in the EMCA specification. + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-051"; +var VERSION = "JS1_4"; +var TITLE = "Examples of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("for (a; b\n) result += \": got to inner loop\";") + } catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "for (a; b\n)" + + " (threw " + exception +")", + expect, + result ); + +test(); + + + diff --git a/js/src/tests/ecma_2/Exceptions/lexical-052.js b/js/src/tests/ecma_2/Exceptions/lexical-052.js new file mode 100644 index 000000000..b134b9743 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-052.js @@ -0,0 +1,47 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-052.js + Corresponds to: 7.8.2-4-n.js + ECMA Section: 7.8.2 Examples of Automatic Semicolon Insertion + Description: compare some specific examples of the automatic + insertion rules in the EMCA specification. + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-052"; +var VERSION = "JS1_4"; +var TITLE = "Examples of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + MyFunction(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "calling return indirectly" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyFunction() { + var s = "return"; + eval(s); +} diff --git a/js/src/tests/ecma_2/Exceptions/lexical-053.js b/js/src/tests/ecma_2/Exceptions/lexical-053.js new file mode 100644 index 000000000..8739afbad --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-053.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-053.js + Corresponds to: 7.8.2-7-n.js + ECMA Section: 7.8.2 Examples of Automatic Semicolon Insertion + Description: compare some specific examples of the automatic + insertion rules in the EMCA specification. + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-053"; +var VERSION = "JS1_4"; +var TITLE = "Examples of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + a = true + b = false + + eval('if (a > b)\nelse result += ": got to else statement"'); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "calling return indirectly" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/lexical-054.js b/js/src/tests/ecma_2/Exceptions/lexical-054.js new file mode 100644 index 000000000..1b6e995c3 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/lexical-054.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: lexical-054.js + Corresponds to: 7.8.2-7-n.js + ECMA Section: 7.8.2 Examples of Automatic Semicolon Insertion + Description: compare some specific examples of the automatic + insertion rules in the EMCA specification. + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "lexical-054"; +var VERSION = "JS1_4"; +var TITLE = "Examples of Automatic Semicolon Insertion"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + a=0; + b=1; + c=2; + d=3; + eval("if (a > b)\nelse c = d"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "if (a > b)\nelse c = d" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/number-001.js b/js/src/tests/ecma_2/Exceptions/number-001.js new file mode 100644 index 000000000..37ba1b798 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/number-001.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: number-001 + Corresponds To: 15.7.4.2-2-n.js + ECMA Section: 15.7.4.2.2 Number.prototype.toString() + Description: + If the radix is the number 10 or not supplied, then this number value is + given as an argument to the ToString operator; the resulting string value + is returned. + + If the radix is supplied and is an integer from 2 to 36, but not 10, the + result is a string, the choice of which is implementation dependent. + + The toString function is not generic; it generates a runtime error if its + this value is not a Number object. Therefore it cannot be transferred to + other kinds of objects for use as a method. + + Author: christine@netscape.com + Date: 16 september 1997 +*/ +var SECTION = "number-001"; +var VERSION = "JS1_4"; +var TITLE = "Exceptions for Number.toString()"; + +startTest(); +writeHeaderToLog( SECTION + " Number.prototype.toString()"); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + object= new Object(); + object.toString = Number.prototype.toString; + result = object.toString(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "object = new Object(); object.toString = Number.prototype.toString; object.toString()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/number-002.js b/js/src/tests/ecma_2/Exceptions/number-002.js new file mode 100644 index 000000000..5f4462e04 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/number-002.js @@ -0,0 +1,48 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: number-002.js + Corresponds To: ecma/Number/15.7.4.3-2-n.js + ECMA Section: 15.7.4.3.1 Number.prototype.valueOf() + Description: + Returns this number value. + + The valueOf function is not generic; it generates a runtime error if its + this value is not a Number object. Therefore it cannot be transferred to + other kinds of objects for use as a method. + + Author: christine@netscape.com + Date: 16 september 1997 +*/ +var SECTION = "number-002"; +var VERSION = "JS1_4"; +var TITLE = "Exceptions for Number.valueOf()"; + +startTest(); +writeHeaderToLog( SECTION + " Number.prototype.valueOf()"); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + object= new Object(); + object.toString = Number.prototype.valueOf; + result = object.toString(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "object = new Object(); object.valueOf = Number.prototype.valueOf; object.valueOf()" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/number-003.js b/js/src/tests/ecma_2/Exceptions/number-003.js new file mode 100644 index 000000000..8d0ad83db --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/number-003.js @@ -0,0 +1,50 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: number-003.js + Corresponds To: 15.7.4.3-3.js + ECMA Section: 15.7.4.3.1 Number.prototype.valueOf() + Description: + Returns this number value. + + The valueOf function is not generic; it generates a runtime error if its + this value is not a Number object. Therefore it cannot be transferred to + other kinds of objects for use as a method. + + Author: christine@netscape.com + Date: 16 september 1997 +*/ +var SECTION = "number-003"; +var VERSION = "JS1_4"; +var TITLE = "Exceptions for Number.valueOf()"; + +startTest(); +writeHeaderToLog( SECTION + " Number.prototype.valueOf()"); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + VALUE_OF = Number.prototype.valueOf; + OBJECT = new String("Infinity"); + OBJECT.valueOf = VALUE_OF; + result = OBJECT.valueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "Assigning Number.prototype.valueOf as the valueOf of a String object " + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/shell.js b/js/src/tests/ecma_2/Exceptions/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/shell.js diff --git a/js/src/tests/ecma_2/Exceptions/statement-001.js b/js/src/tests/ecma_2/Exceptions/statement-001.js new file mode 100644 index 000000000..087f3f74d --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-001.js @@ -0,0 +1,47 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-001.js + Corresponds To: 12.6.2-9-n.js + ECMA Section: 12.6.2 The for Statement + + 1. first expression is not present. + 2. second expression is not present + 3. third expression is not present + + + Author: christine@netscape.com + Date: 15 september 1997 +*/ + +var SECTION = "statement-001.js"; +// var SECTION = "12.6.2-9-n"; +var VERSION = "ECMA_1"; +var TITLE = "The for statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("for (i) {\n}"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "for(i) {}" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/statement-002.js b/js/src/tests/ecma_2/Exceptions/statement-002.js new file mode 100644 index 000000000..7ac633058 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-002.js @@ -0,0 +1,69 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-002.js + Corresponds To: 12.6.3-1.js + ECMA Section: 12.6.3 The for...in Statement + Description: + The production IterationStatement : for ( LeftHandSideExpression in Expression ) + Statement is evaluated as follows: + + 1. Evaluate the Expression. + 2. Call GetValue(Result(1)). + 3. Call ToObject(Result(2)). + 4. Let C be "normal completion". + 5. Get the name of the next property of Result(3) that doesn't have the + DontEnum attribute. If there is no such property, go to step 14. + 6. Evaluate the LeftHandSideExpression ( it may be evaluated repeatedly). + 7. Call PutValue(Result(6), Result(5)). PutValue( V, W ): + 1. If Type(V) is not Reference, generate a runtime error. + 2. Call GetBase(V). + 3. If Result(2) is null, go to step 6. + 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V) + for the property name and W for the value. + 5. Return. + 6. Call the [[Put]] method for the global object, passing + GetPropertyName(V) for the property name and W for the value. + 7. Return. + 8. Evaluate Statement. + 9. If Result(8) is a value completion, change C to be "normal completion + after value V" where V is the value carried by Result(8). + 10. If Result(8) is a break completion, go to step 14. + 11. If Result(8) is a continue completion, go to step 5. + 12. If Result(8) is a return completion, return Result(8). + 13. Go to step 5. + 14. Return C. + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "statement-002"; +var VERSION = "JS1_4"; +var TITLE = "The for..in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval(" for ( var i, p in this) { result += this[p]; }"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "more than one member expression" + + " (threw " + exception +")", + expect, + result ); + +test(); diff --git a/js/src/tests/ecma_2/Exceptions/statement-003.js b/js/src/tests/ecma_2/Exceptions/statement-003.js new file mode 100644 index 000000000..7e257675c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-003.js @@ -0,0 +1,80 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-003 + Corresponds To: 12.6.3-7-n.js + ECMA Section: 12.6.3 The for...in Statement + Description: + The production IterationStatement : for ( LeftHandSideExpression in Expression ) + Statement is evaluated as follows: + + 1. Evaluate the Expression. + 2. Call GetValue(Result(1)). + 3. Call ToObject(Result(2)). + 4. Let C be "normal completion". + 5. Get the name of the next property of Result(3) that doesn't have the + DontEnum attribute. If there is no such property, go to step 14. + 6. Evaluate the LeftHandSideExpression ( it may be evaluated repeatedly). + 7. Call PutValue(Result(6), Result(5)). PutValue( V, W ): + 1. If Type(V) is not Reference, generate a runtime error. + 2. Call GetBase(V). + 3. If Result(2) is null, go to step 6. + 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V) + for the property name and W for the value. + 5. Return. + 6. Call the [[Put]] method for the global object, passing + GetPropertyName(V) for the property name and W for the value. + 7. Return. + 8. Evaluate Statement. + 9. If Result(8) is a value completion, change C to be "normal completion + after value V" where V is the value carried by Result(8). + 10. If Result(8) is a break completion, go to step 14. + 11. If Result(8) is a continue completion, go to step 5. + 12. If Result(8) is a return completion, return Result(8). + 13. Go to step 5. + 14. Return C. + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "statement-003"; +var VERSION = "JS1_4"; +var TITLE = "The for..in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var o = new MyObject(); + var result = 0; + + eval("for ( this in o) {\n" + + "result += this[p];\n" + + "}\n"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "bad left-hand side expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyObject() { + this.value = 2; + this[0] = 4; + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/statement-004.js b/js/src/tests/ecma_2/Exceptions/statement-004.js new file mode 100644 index 000000000..056e0452e --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-004.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-004.js + Corresponds To: 12.6.3-1.js + ECMA Section: 12.6.3 The for...in Statement + Description: + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "statement-004"; +var VERSION = "JS1_4"; +var TITLE = "The for..in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var o = new MyObject(); + + eval("for ( \"a\" in o) {\n" + + "result += this[p];\n" + + "}"); + +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "bad left-hand side expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + + +function MyObject() { + this.value = 2; + this[0] = 4; + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/statement-005.js b/js/src/tests/ecma_2/Exceptions/statement-005.js new file mode 100644 index 000000000..404a157e9 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-005.js @@ -0,0 +1,51 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-005.js + Corresponds To: 12.6.3-8-n.js + ECMA Section: 12.6.3 The for...in Statement + Description: + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "statement-005"; +var VERSION = "JS1_4"; +var TITLE = "The for..in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var o = new MyObject(); + result = 0; + + eval("for (1 in o) {\n" + + "result += this[p];" + + "}\n"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "bad left-hand side expression" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyObject() { + this.value = 2; + this[0] = 4; + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/statement-006.js b/js/src/tests/ecma_2/Exceptions/statement-006.js new file mode 100644 index 000000000..24839d847 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-006.js @@ -0,0 +1,51 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-006.js + Corresponds To: 12.6.3-9-n.js + ECMA Section: 12.6.3 The for...in Statement + Description: + + Author: christine@netscape.com + Date: 11 september 1997 +*/ +var SECTION = "statement-006"; +var VERSION = "JS1_4"; +var TITLE = "The for..in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var o = new MyObject(); + var result = 0; + for ( var o in foo) { + result += this[o]; + } +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "object is not defined" + + " (threw " + exception +")", + expect, + result ); + +test(); + +function MyObject() { + this.value = 2; + this[0] = 4; + return this; +} diff --git a/js/src/tests/ecma_2/Exceptions/statement-007.js b/js/src/tests/ecma_2/Exceptions/statement-007.js new file mode 100644 index 000000000..bb561b691 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-007.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-007.js + Corresponds To: 12.7-1-n.js + ECMA Section: 12.7 The continue statement + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "statement-007"; +var VERSION = "JS1_4"; +var TITLE = "The continue statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("continue;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "continue outside of an iteration statement" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/statement-008.js b/js/src/tests/ecma_2/Exceptions/statement-008.js new file mode 100644 index 000000000..a71fc266d --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-008.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: statement-008.js + Corresponds To: 12.8-1-n.js + ECMA Section: 12.8 The break statement + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "statement-008"; +var VERSION = "JS1_4"; +var TITLE = "The break in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("break;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "break outside of an iteration statement" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/statement-009.js b/js/src/tests/ecma_2/Exceptions/statement-009.js new file mode 100644 index 000000000..9be1de747 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/statement-009.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: 12.9-1-n.js + ECMA Section: 12.9 The return statement + Description: + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "12.9-1-n"; +var VERSION = "ECMA_1"; +var TITLE = "The return statement"; + +startTest(); +writeHeaderToLog( SECTION + " The return statement"); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + eval("return;"); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "return outside of a function" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/string-001.js b/js/src/tests/ecma_2/Exceptions/string-001.js new file mode 100644 index 000000000..68bfe181c --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/string-001.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: string-001.js + Corresponds To: 15.5.4.2-2-n.js + ECMA Section: 15.5.4.2 String.prototype.toString() + + Description: Returns this string value. Note that, for a String + object, the toString() method happens to return the same + thing as the valueOf() method. + + The toString function is not generic; it generates a + runtime error if its this value is not a String object. + Therefore it connot be transferred to the other kinds of + objects for use as a method. + + Author: christine@netscape.com + Date: 1 october 1997 +*/ +var SECTION = "string-001"; +var VERSION = "JS1_4"; +var TITLE = "String.prototype.toString"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + OBJECT = new Object(); + OBJECT.toString = String.prototype.toString(); + result = OBJECT.toString(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "OBJECT = new Object; "+ + " OBJECT.toString = String.prototype.toString; OBJECT.toString()" + + " (threw " + exception +")", + expect, + result ); + +test(); + diff --git a/js/src/tests/ecma_2/Exceptions/string-002.js b/js/src/tests/ecma_2/Exceptions/string-002.js new file mode 100644 index 000000000..b68f2a156 --- /dev/null +++ b/js/src/tests/ecma_2/Exceptions/string-002.js @@ -0,0 +1,52 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: string-002.js + Corresponds To: 15.5.4.3-3-n.js + ECMA Section: 15.5.4.3 String.prototype.valueOf() + + Description: Returns this string value. + + The valueOf function is not generic; it generates a + runtime error if its this value is not a String object. + Therefore it connot be transferred to the other kinds of + objects for use as a method. + + Author: christine@netscape.com + Date: 1 october 1997 +*/ +var SECTION = "string-002"; +var VERSION = "JS1_4"; +var TITLE = "String.prototype.valueOf"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var result = "Failed"; +var exception = "No exception thrown"; +var expect = "Passed"; + +try { + var OBJECT =new Object(); + OBJECT.valueOf = String.prototype.valueOf; + result = OBJECT.valueOf(); +} catch ( e ) { + result = expect; + exception = e.toString(); +} + +new TestCase( + SECTION, + "OBJECT = new Object; OBJECT.valueOf = String.prototype.valueOf;"+ + "result = OBJECT.valueOf();" + + " (threw " + exception +")", + expect, + result ); + +test(); + + diff --git a/js/src/tests/ecma_2/Expressions/StrictEquality-001.js b/js/src/tests/ecma_2/Expressions/StrictEquality-001.js new file mode 100644 index 000000000..c96d1be3e --- /dev/null +++ b/js/src/tests/ecma_2/Expressions/StrictEquality-001.js @@ -0,0 +1,73 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: StrictEquality-001.js + * ECMA Section: 11.9.6.js + * Description: + * + * Author: christine@netscape.com + * Date: 4 september 1998 + */ +var SECTION = "StrictEquality-001 - 11.9.6"; +var VERSION = "ECMA_2"; +var TITLE = "The strict equality operator ( === )"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 1. If Type(x) is different from Type(y) return false + +StrictEquality( true, new Boolean(true), false ); +StrictEquality( new Boolean(), false, false ); +StrictEquality( "", new String(), false ); +StrictEquality( new String("hi"), "hi", false ); + +// 2. If Type(x) is not Number go to step 9. + +// 3. If x is NaN, return false +StrictEquality( NaN, NaN, false ); +StrictEquality( NaN, 0, false ); + +// 4. If y is NaN, return false. +StrictEquality( 0, NaN, false ); + +// 5. if x is the same number value as y, return true + +// 6. If x is +0 and y is -0, return true + +// 7. If x is -0 and y is +0, return true + +// 8. Return false. + + +// 9. If Type(x) is String, then return true if x and y are exactly +// the same sequence of characters ( same length and same characters +// in corresponding positions.) Otherwise return false. + +// 10. If Type(x) is Boolean, return true if x and y are both true or +// both false. otherwise return false. + + +// Return true if x and y refer to the same object. Otherwise return +// false. + +// Return false. + + +test(); + +function StrictEquality( x, y, expect ) { + result = ( x === y ); + + new TestCase( + SECTION, + x +" === " + y, + expect, + result ); +} + diff --git a/js/src/tests/ecma_2/Expressions/browser.js b/js/src/tests/ecma_2/Expressions/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Expressions/browser.js diff --git a/js/src/tests/ecma_2/Expressions/shell.js b/js/src/tests/ecma_2/Expressions/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Expressions/shell.js diff --git a/js/src/tests/ecma_2/FunctionObjects/apply-001-n.js b/js/src/tests/ecma_2/FunctionObjects/apply-001-n.js new file mode 100644 index 000000000..eac058446 --- /dev/null +++ b/js/src/tests/ecma_2/FunctionObjects/apply-001-n.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +print("STATUS: f.apply crash test."); + +print("BUGNUMBER: 21836"); + +function f () +{ +} + +var SECTION = "apply-001-n"; +var VERSION = "ECMA_1"; +startTest(); +var TITLE = "f.apply(2,2) doesn't crash"; + +writeHeaderToLog( SECTION + " "+ TITLE); + +DESCRIPTION = "f.apply(2,2) doesn't crash"; +EXPECTED = "error"; + +new TestCase( SECTION, "f.apply(2,2) doesn't crash", "error", eval("f.apply(2,2)") ); + +test(); + + diff --git a/js/src/tests/ecma_2/FunctionObjects/browser.js b/js/src/tests/ecma_2/FunctionObjects/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/FunctionObjects/browser.js diff --git a/js/src/tests/ecma_2/FunctionObjects/call-1.js b/js/src/tests/ecma_2/FunctionObjects/call-1.js new file mode 100644 index 000000000..9ff19555e --- /dev/null +++ b/js/src/tests/ecma_2/FunctionObjects/call-1.js @@ -0,0 +1,42 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: call-1.js + Section: Function.prototype.call + Description: + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = "call-1"; +var VERSION = "ECMA_2"; +var TITLE = "Function.prototype.call"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +new TestCase( SECTION, + "ConvertToString.call(this, this)", + GLOBAL, + ConvertToString.call(this, this)); + +new TestCase( SECTION, + "ConvertToString.call(Boolean, Boolean.prototype)", + "false", + ConvertToString.call(Boolean, Boolean.prototype)); + +new TestCase( SECTION, + "ConvertToString.call(Boolean, Boolean.prototype.valueOf())", + "false", + ConvertToString.call(Boolean, Boolean.prototype.valueOf())); + +test(); + +function ConvertToString(obj) { + return obj +""; +} diff --git a/js/src/tests/ecma_2/FunctionObjects/shell.js b/js/src/tests/ecma_2/FunctionObjects/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/FunctionObjects/shell.js diff --git a/js/src/tests/ecma_2/LexicalConventions/browser.js b/js/src/tests/ecma_2/LexicalConventions/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/LexicalConventions/browser.js diff --git a/js/src/tests/ecma_2/LexicalConventions/keywords-001.js b/js/src/tests/ecma_2/LexicalConventions/keywords-001.js new file mode 100644 index 000000000..411386100 --- /dev/null +++ b/js/src/tests/ecma_2/LexicalConventions/keywords-001.js @@ -0,0 +1,48 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: + * ECMA Section: + * Description: + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = ""; +var VERSION = "ECMA_2"; +var TITLE = "Keywords"; + +startTest(); + +print("This test requires option javascript.options.strict enabled"); + +if (!options().match(/strict/)) +{ + options('strict'); +} +if (!options().match(/werror/)) +{ + options('werror'); +} + +var result = "failed"; + +try { + eval("super;"); +} +catch (x) { + if (x instanceof SyntaxError) + result = x.name; +} + +AddTestCase( + "using the expression \"super\" shouldn't cause js to crash", + "SyntaxError", + result ); + +test(); diff --git a/js/src/tests/ecma_2/LexicalConventions/regexp-literals-001.js b/js/src/tests/ecma_2/LexicalConventions/regexp-literals-001.js new file mode 100644 index 000000000..cb2448d1e --- /dev/null +++ b/js/src/tests/ecma_2/LexicalConventions/regexp-literals-001.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: LexicalConventions/regexp-literals-001.js + * ECMA Section: 7.8.5 + * Description: + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "LexicalConventions/regexp-literals-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "Regular Expression Literals"; + +startTest(); + +// Regular Expression Literals may not be empty; // should be regarded +// as a comment, not a RegExp literal. + +s = //; + + "passed"; + +AddTestCase( + "// should be a comment, not a regular expression literal", + "passed", + String(s)); + +AddTestCase( + "// typeof object should be type of object declared on following line", + "passed", + (typeof s) == "string" ? "passed" : "failed" ); + +AddTestCase( + "// should not return an object of the type RegExp", + "passed", + (typeof s == "object") ? "failed" : "passed" ); + +test(); diff --git a/js/src/tests/ecma_2/LexicalConventions/regexp-literals-002.js b/js/src/tests/ecma_2/LexicalConventions/regexp-literals-002.js new file mode 100644 index 000000000..5b256dd22 --- /dev/null +++ b/js/src/tests/ecma_2/LexicalConventions/regexp-literals-002.js @@ -0,0 +1,28 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: LexicalConventions/regexp-literals-002.js + * ECMA Section: 7.8.5 + * Description: Based on ECMA 2 Draft 8 October 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "LexicalConventions/regexp-literals-002.js"; +var VERSION = "ECMA_2"; +var TITLE = "Regular Expression Literals"; + +startTest(); + +// A regular expression literal represents an object of type RegExp. + +AddTestCase( + "// A regular expression literal represents an object of type RegExp.", + "true", + (/x*/ instanceof RegExp).toString() ); + +test(); diff --git a/js/src/tests/ecma_2/LexicalConventions/shell.js b/js/src/tests/ecma_2/LexicalConventions/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/LexicalConventions/shell.js diff --git a/js/src/tests/ecma_2/README b/js/src/tests/ecma_2/README new file mode 100644 index 000000000..6da6cdd51 --- /dev/null +++ b/js/src/tests/ecma_2/README @@ -0,0 +1 @@ +ECMA 262 Edition 2 diff --git a/js/src/tests/ecma_2/RegExp/browser.js b/js/src/tests/ecma_2/RegExp/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/browser.js diff --git a/js/src/tests/ecma_2/RegExp/constructor-001.js b/js/src/tests/ecma_2/RegExp/constructor-001.js new file mode 100644 index 000000000..b268ae5ed --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/constructor-001.js @@ -0,0 +1,66 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/constructor-001.js + * ECMA Section: 15.7.3.3 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/constructor-001"; +var VERSION = "ECMA_2"; +var TITLE = "new RegExp()"; + +startTest(); + +/* + * for each test case, verify: + * - verify that [[Class]] property is RegExp + * - prototype property should be set to RegExp.prototype + * - source is set to the empty string + * - global property is set to false + * - ignoreCase property is set to false + * - multiline property is set to false + * - lastIndex property is set to 0 + */ + +RegExp.prototype.getClassProperty = Object.prototype.toString; +var re = new RegExp(); + +AddTestCase( + "RegExp.prototype.getClassProperty = Object.prototype.toString; " + + "(new RegExp()).getClassProperty()", + "[object RegExp]", + re.getClassProperty() ); + +AddTestCase( + "(new RegExp()).source", + "(?:)", + re.source ); + +AddTestCase( + "(new RegExp()).global", + false, + re.global ); + +AddTestCase( + "(new RegExp()).ignoreCase", + false, + re.ignoreCase ); + +AddTestCase( + "(new RegExp()).multiline", + false, + re.multiline ); + +AddTestCase( + "(new RegExp()).lastIndex", + 0, + re.lastIndex ); + +test() diff --git a/js/src/tests/ecma_2/RegExp/exec-001.js b/js/src/tests/ecma_2/RegExp/exec-001.js new file mode 100644 index 000000000..18ced9068 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/exec-001.js @@ -0,0 +1,41 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/exec-001.js + * ECMA Section: 15.7.5.3 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/exec-001"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp.prototype.exec(string)"; + +startTest(); + +/* + * for each test case, verify: + * - type of object returned + * - length of the returned array + * - value of lastIndex + * - value of index + * - value of input + * - value of the array indices + */ + +// test cases without subpatterns +// test cases with subpatterns +// global property is true +// global property is false +// test cases in which the exec returns null + +AddTestCase("NO TESTS EXIST", "PASSED", "Test not implemented"); + +test(); + diff --git a/js/src/tests/ecma_2/RegExp/exec-002.js b/js/src/tests/ecma_2/RegExp/exec-002.js new file mode 100644 index 000000000..86d8ccb9a --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/exec-002.js @@ -0,0 +1,188 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/exec-002.js + * ECMA Section: 15.7.5.3 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Test cases provided by rogerl@netscape.com + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/exec-002"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp.prototype.exec(string)"; + +startTest(); + +/* + * for each test case, verify: + * - type of object returned + * - length of the returned array + * - value of lastIndex + * - value of index + * - value of input + * - value of the array indices + */ + +AddRegExpCases( + /(a|d|q|)x/i, + "bcaDxqy", + 3, + ["Dx", "D"] ); + +AddRegExpCases( + /(a|(e|q))(x|y)/, + "bcaddxqy", + 6, + ["qy","q","q","y"] ); + + +AddRegExpCases( + /a+b+d/, + "aabbeeaabbs", + 0, + null ); + +AddRegExpCases( + /a*b/, + "aaadaabaaa", + 4, + ["aab"] ); + +AddRegExpCases( + /a*b/, + "dddb", + 3, + ["b"] ); + +AddRegExpCases( + /a*b/, + "xxx", + 0, + null ); + +AddRegExpCases( + /x\d\dy/, + "abcx45ysss235", + 3, + ["x45y"] ); + +AddRegExpCases( + /[^abc]def[abc]+/, + "abxdefbb", + 2, + ["xdefbb"] ); + +AddRegExpCases( + /(a*)baa/, + "ccdaaabaxaabaa", + 9, + ["aabaa", "aa"] ); + +AddRegExpCases( + /(a*)baa/, + "aabaa", + 0, + ["aabaa", "aa"] ); + +AddRegExpCases( + /q(a|b)*q/, + "xxqababqyy", + 2, + ["qababq", "b"] ); + +AddRegExpCases( + /(a(.|[^d])c)*/, + "adcaxc", + 0, + ["adcaxc", "axc", "x"] ); + +AddRegExpCases( + /(a*)b\1/, + "abaaaxaabaayy", + 0, + ["aba", "a"] ); + +AddRegExpCases( + /(a*)b\1/, + "abaaaxaabaayy", + 0, + ["aba", "a"] ); + +AddRegExpCases( + /(a*)b\1/, + "cccdaaabaxaabaayy", + 6, + ["aba", "a"] ); + +AddRegExpCases( + /(a*)b\1/, + "cccdaaabqxaabaayy", + 7, + ["b", ""] ); + +AddRegExpCases( + /"(.|[^"\\\\])*"/, + 'xx\"makudonarudo\"yy', + 2, + ["\"makudonarudo\"", "o"] ); + + AddRegExpCases( + /"(.|[^"\\\\])*"/, + "xx\"ma\"yy", + 2, + ["\"ma\"", "a"] ); + + test(); + + function AddRegExpCases( + regexp, pattern, index, matches_array ) { + +// prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + AddTestCase( + regexp + ".exec(" + pattern +").length", + matches_array.length, + regexp.exec(pattern).length ); + + AddTestCase( + regexp + ".exec(" + pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + regexp + ".exec(" + pattern +").input", + pattern, + regexp.exec(pattern).input ); + + AddTestCase( + regexp + ".exec(" + pattern +").toString()", + matches_array.toString(), + regexp.exec(pattern).toString() ); +/* + var limit = matches_array.length > regexp.exec(pattern).length + ? matches_array.length + : regexp.exec(pattern).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + regexp + ".exec(" + pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +*/ + } diff --git a/js/src/tests/ecma_2/RegExp/hex-001.js b/js/src/tests/ecma_2/RegExp/hex-001.js new file mode 100644 index 000000000..04c3a97b9 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/hex-001.js @@ -0,0 +1,68 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/hex-001.js + * ECMA Section: 15.7.3.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * Positive test cases for constructing a RegExp object + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/hex-001"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp patterns that contain HexicdecimalEscapeSequences"; + +startTest(); + +// These examples come from 15.7.1, HexidecimalEscapeSequence + +AddRegExpCases( new RegExp("\x41"), "new RegExp('\\x41')", "A", "A", 1, 0, ["A"] ); +AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] ); + +AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x41", "\\x41", 1, 0, ["A"] ); +AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x412", "\\x412", 1, 0, ["A"] ); +AddRegExpCases( new RegExp("^x"), "new RegExp('^x')", "x412", "x412", 1, 0, ["x"]); +AddRegExpCases( new RegExp("A"), "new RegExp('A')", "A2", "A2", 1, 0, ["A"] ); + +test(); + +function AddRegExpCases( + regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + str_regexp + ".exec(" + pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").length", + length, + regexp.exec(pattern).length ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").input", + pattern, + regexp.exec(pattern).input ); + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + str_regexp + ".exec(" + str_pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/RegExp/multiline-001.js b/js/src/tests/ecma_2/RegExp/multiline-001.js new file mode 100644 index 000000000..9e69022d5 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/multiline-001.js @@ -0,0 +1,68 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/multiline-001.js + * ECMA Section: + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Date: 19 February 1999 + */ + +var SECTION = "RegExp/multiline-001"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp: multiline flag"; +var BUGNUMBER="343901"; + +startTest(); + +var woodpeckers = "ivory-billed\ndowny\nhairy\nacorn\nyellow-bellied sapsucker\n" + + "northern flicker\npileated\n"; + +AddRegExpCases( /.*[y]$/m, woodpeckers, woodpeckers.indexOf("downy"), ["downy"] ); + +AddRegExpCases( /.*[d]$/m, woodpeckers, woodpeckers.indexOf("ivory-billed"), ["ivory-billed"] ); + +test(); + + +function AddRegExpCases +( regexp, pattern, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + + AddTestCase( + regexp.toString() + ".exec(" + pattern +").length", + matches_array.length, + regexp.exec(pattern).length ); + + AddTestCase( + regexp.toString() + ".exec(" + pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + regexp + ".exec(" + pattern +").input", + pattern, + regexp.exec(pattern).input ); + + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + regexp + ".exec(" + pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/RegExp/octal-001.js b/js/src/tests/ecma_2/RegExp/octal-001.js new file mode 100644 index 000000000..0aa1d0407 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/octal-001.js @@ -0,0 +1,78 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/octal-001.js + * ECMA Section: 15.7.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * Simple test cases for matching OctalEscapeSequences. + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/octal-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp patterns that contain OctalEscapeSequences"; +var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346196"; + +startTest(); + + +// backreference +AddRegExpCases( + /(.)\1/, + "/(.)\\1/", + "HI!!", + "HI!", + 2, + ["!!", "!"] ); + +test(); + +function AddRegExpCases( + regexp, str_regexp, pattern, str_pattern, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + str_pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + AddTestCase( + str_regexp + ".exec(" + str_pattern +").length", + matches_array.length, + regexp.exec(pattern).length ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").input", + pattern, + regexp.exec(pattern).input ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").toString()", + matches_array.toString(), + regexp.exec(pattern).toString() ); +/* + var limit = matches_array.length > regexp.exec(pattern).length + ? matches_array.length + : regexp.exec(pattern).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + str_regexp + ".exec(" + str_pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +*/ +} diff --git a/js/src/tests/ecma_2/RegExp/octal-002.js b/js/src/tests/ecma_2/RegExp/octal-002.js new file mode 100644 index 000000000..309fff473 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/octal-002.js @@ -0,0 +1,93 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/octal-002.js + * ECMA Section: 15.7.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * Simple test cases for matching OctalEscapeSequences. + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/octal-002.js"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp patterns that contain OctalEscapeSequences"; +var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346189"; + +startTest(); + +// backreference +AddRegExpCases( + /(.)(.)(.)(.)(.)(.)(.)(.)\8/, + "/(.)(.)(.)(.)(.)(.)(.)(.)\\8", + "aabbccaaabbbccc", + "aabbccaaabbbccc", + 0, + ["aabbccaaa", "a", "a", "b", "b", "c", "c", "a", "a"] ); + +AddRegExpCases( + /(.)(.)(.)(.)(.)(.)(.)(.)(.)\9/, + "/(.)(.)(.)(.)(.)(.)(.)(.)\\9", + "aabbccaabbcc", + "aabbccaabbcc", + 0, + ["aabbccaabb", "a", "a", "b", "b", "c", "c", "a", "a", "b"] ); + +AddRegExpCases( + /(.)(.)(.)(.)(.)(.)(.)(.)(.)\8/, + "/(.)(.)(.)(.)(.)(.)(.)(.)(.)\\8", + "aabbccaababcc", + "aabbccaababcc", + 0, + ["aabbccaaba", "a", "a", "b", "b", "c", "c", "a", "a", "b"] ); + +test(); + +function AddRegExpCases( + regexp, str_regexp, pattern, str_pattern, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + str_pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + AddTestCase( + str_regexp + ".exec(" + str_pattern +").length", + matches_array.length, + regexp.exec(pattern).length ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").input", + pattern, + regexp.exec(pattern).input ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").toString()", + matches_array.toString(), + regexp.exec(pattern).toString() ); +/* + var limit = matches_array.length > regexp.exec(pattern).length + ? matches_array.length + : regexp.exec(pattern).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + str_regexp + ".exec(" + str_pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +*/ +} diff --git a/js/src/tests/ecma_2/RegExp/octal-003.js b/js/src/tests/ecma_2/RegExp/octal-003.js new file mode 100644 index 000000000..a73d7d40e --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/octal-003.js @@ -0,0 +1,87 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/octal-003.js + * ECMA Section: 15.7.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * Simple test cases for matching OctalEscapeSequences. + * Author: christine@netscape.com + * Date: 19 February 1999 + * + * Revised: 02 August 2002 + * Author: pschwartau@netscape.com + * + * WHY: the original test expected the regexp /.\011/ + * to match 'a' + String.fromCharCode(0) + '11' + * + * This is incorrect: the string is a 4-character string consisting of + * the characters <'a'>, <nul>, <'1'>, <'1'>. By contrast, the \011 in the + * regexp should be parsed as a single token: it is the octal escape sequence + * for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'. + * + * So the regexp consists of 2 characters: <any-character>, <'\t'>. + * There is no match between the regexp and the string. + * + * See the testcase ecma_3/RegExp/octal-002.js for an elaboration. + * + */ +var SECTION = "RegExp/octal-003.js"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp patterns that contain OctalEscapeSequences"; +var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132"; + +startTest(); + +AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null ); + +test(); + +function AddRegExpCases( + regexp, str_regexp, pattern, str_pattern, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(pattern) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + str_pattern +")", + matches_array, + regexp.exec(pattern) ); + + return; + } + AddTestCase( + str_regexp + ".exec(" + str_pattern +").length", + matches_array.length, + regexp.exec(pattern).length ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").input", + escape(pattern), + escape(regexp.exec(pattern).input) ); + + AddTestCase( + str_regexp + ".exec(" + str_pattern +").toString()", + matches_array.toString(), + escape(regexp.exec(pattern).toString()) ); + + var limit = matches_array.length > regexp.exec(pattern).length + ? matches_array.length + : regexp.exec(pattern).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + str_regexp + ".exec(" + str_pattern +")[" + matches +"]", + matches_array[matches], + escape(regexp.exec(pattern)[matches]) ); + } + +} diff --git a/js/src/tests/ecma_2/RegExp/properties-001.js b/js/src/tests/ecma_2/RegExp/properties-001.js new file mode 100644 index 000000000..b0ee18e20 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/properties-001.js @@ -0,0 +1,91 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/properties-001.js + * ECMA Section: 15.7.6.js + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/properties-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "Properties of RegExp Instances"; +var BUGNUMBER =""; + +startTest(); + +AddRegExpCases( new RegExp, "(?:)", false, false, false, 0 ); +AddRegExpCases( /.*/, ".*", false, false, false, 0 ); +AddRegExpCases( /[\d]{5}/g, "[\\d]{5}", true, false, false, 0 ); +AddRegExpCases( /[\S]?$/i, "[\\S]?$", false, true, false, 0 ); +AddRegExpCases( /^([a-z]*)[^\w\s\f\n\r]+/m, "^([a-z]*)[^\\w\\s\\f\\n\\r]+", false, false, true, 0 ); +AddRegExpCases( /[\D]{1,5}[\ -][\d]/gi, "[\\D]{1,5}[\\ -][\\d]", true, true, false, 0 ); +AddRegExpCases( /[a-zA-Z0-9]*/gm, "[a-zA-Z0-9]*", true, false, true, 0 ); +AddRegExpCases( /x|y|z/gim, "x|y|z", true, true, true, 0 ); + +AddRegExpCases( /\u0051/im, "\\u0051", false, true, true, 0 ); +AddRegExpCases( /\x45/gm, "\\x45", true, false, true, 0 ); +AddRegExpCases( /\097/gi, "\\097", true, true, false, 0 ); + +test(); + +function AddRegExpCases( re, s, g, i, m, l ) { + + AddTestCase( re + ".test == RegExp.prototype.test", + true, + re.test == RegExp.prototype.test ); + + AddTestCase( re + ".toString == RegExp.prototype.toString", + true, + re.toString == RegExp.prototype.toString ); + + AddTestCase( re + ".contructor == RegExp.prototype.constructor", + true, + re.constructor == RegExp.prototype.constructor ); + + AddTestCase( re + ".compile == RegExp.prototype.compile", + true, + re.compile == RegExp.prototype.compile ); + + AddTestCase( re + ".exec == RegExp.prototype.exec", + true, + re.exec == RegExp.prototype.exec ); + + // properties + + AddTestCase( re + ".source", + s, + re.source ); + +/* + * http://bugzilla.mozilla.org/show_bug.cgi?id=225550 changed + * the behavior of toString() and toSource() on empty regexps. + * So branch if |s| is the empty string - + */ + var S = s? s : '(?:)'; + + AddTestCase( re + ".toString()", + "/" + S +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""), + re.toString() ); + + AddTestCase( re + ".global", + g, + re.global ); + + AddTestCase( re + ".ignoreCase", + i, + re.ignoreCase ); + + AddTestCase( re + ".multiline", + m, + re.multiline); + + AddTestCase( re + ".lastIndex", + l, + re.lastIndex ); +} diff --git a/js/src/tests/ecma_2/RegExp/properties-002.js b/js/src/tests/ecma_2/RegExp/properties-002.js new file mode 100644 index 000000000..330fe4bd5 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/properties-002.js @@ -0,0 +1,129 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/properties-002.js + * ECMA Section: 15.7.6.js + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +//----------------------------------------------------------------------------- +var SECTION = "RegExp/properties-002.js"; +var VERSION = "ECMA_2"; +var TITLE = "Properties of RegExp Instances"; +var BUGNUMBER ="124339"; + +startTest(); + +re_1 = /\cA?/g; +re_1.lastIndex = Math.pow(2,31); +AddRegExpCases( re_1, "\\cA?", true, false, false, Math.pow(2,31) ); + +re_2 = /\w*/i; +re_2.lastIndex = Math.pow(2,32) -1; +AddRegExpCases( re_2, "\\w*", false, true, false, Math.pow(2,32)-1 ); + +re_3 = /\*{0,80}/m; +re_3.lastIndex = Math.pow(2,31) -1; +AddRegExpCases( re_3, "\\*{0,80}", false, false, true, Math.pow(2,31) -1 ); + +re_4 = /^./gim; +re_4.lastIndex = Math.pow(2,30) -1; +AddRegExpCases( re_4, "^.", true, true, true, Math.pow(2,30) -1 ); + +re_5 = /\B/; +re_5.lastIndex = Math.pow(2,30); +AddRegExpCases( re_5, "\\B", false, false, false, Math.pow(2,30) ); + +/* + * Brendan: "need to test cases Math.pow(2,32) and greater to see + * whether they round-trip." Reason: thanks to the work done in + * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, lastIndex + * is now stored as a double instead of a uint32_t (unsigned integer). + * + * Note 2^32 -1 is the upper bound for uint32's, but doubles can go + * all the way up to Number.MAX_VALUE. So that's why we need cases + * between those two numbers. + * + */ +re_6 = /\B/; +re_6.lastIndex = Math.pow(2,32); +AddRegExpCases( re_6, "\\B", false, false, false, Math.pow(2,32) ); + +re_7 = /\B/; +re_7.lastIndex = Math.pow(2,32) + 1; +AddRegExpCases( re_7, "\\B", false, false, false, Math.pow(2,32) + 1 ); + +re_8 = /\B/; +re_8.lastIndex = Math.pow(2,32) * 2; +AddRegExpCases( re_8, "\\B", false, false, false, Math.pow(2,32) * 2 ); + +re_9 = /\B/; +re_9.lastIndex = Math.pow(2,40); +AddRegExpCases( re_9, "\\B", false, false, false, Math.pow(2,40) ); + +re_10 = /\B/; +re_10.lastIndex = Number.MAX_VALUE; +AddRegExpCases( re_10, "\\B", false, false, false, Number.MAX_VALUE ); + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + + +function AddRegExpCases( re, s, g, i, m, l ){ + + AddTestCase( re + ".test == RegExp.prototype.test", + true, + re.test == RegExp.prototype.test ); + + AddTestCase( re + ".toString == RegExp.prototype.toString", + true, + re.toString == RegExp.prototype.toString ); + + AddTestCase( re + ".contructor == RegExp.prototype.constructor", + true, + re.constructor == RegExp.prototype.constructor ); + + AddTestCase( re + ".compile == RegExp.prototype.compile", + true, + re.compile == RegExp.prototype.compile ); + + AddTestCase( re + ".exec == RegExp.prototype.exec", + true, + re.exec == RegExp.prototype.exec ); + + // properties + + AddTestCase( re + ".source", + s, + re.source ); + + AddTestCase( re + ".toString()", + "/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""), + re.toString() ); + + AddTestCase( re + ".global", + g, + re.global ); + + AddTestCase( re + ".ignoreCase", + i, + re.ignoreCase ); + + AddTestCase( re + ".multiline", + m, + re.multiline); + + AddTestCase( re + ".lastIndex", + l, + re.lastIndex ); +} diff --git a/js/src/tests/ecma_2/RegExp/regexp-enumerate-001.js b/js/src/tests/ecma_2/RegExp/regexp-enumerate-001.js new file mode 100644 index 000000000..d1f3f213e --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/regexp-enumerate-001.js @@ -0,0 +1,88 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: regexp-enumerate-001.js + ECMA V2 Section: + Description: Regression Test. + + If instance Native Object have properties that are enumerable, + JavaScript enumerated through the properties twice. This only + happened if objects had been instantiated, but their properties + had not been enumerated. ie, the object inherited properties + from its prototype that are enumerated. + + In the core JavaScript, this is only a problem with RegExp + objects, since the inherited properties of most core JavaScript + objects are not enumerated. + + Author: christine@netscape.com, pschwartau@netscape.com + Date: 12 November 1997 + Modified: 14 July 2002 + Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155291 + ECMA-262 Ed.3 Sections 15.10.7.1 through 15.10.7.5 + RegExp properties should be DontEnum + * + */ +// onerror = err; + +var SECTION = "regexp-enumerate-001"; +var VERSION = "ECMA_2"; +var TITLE = "Regression Test for Enumerating Properties"; + +var BUGNUMBER="339403"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +/* + * This test expects RegExp instances to have four enumerated properties: + * source, global, ignoreCase, and lastIndex + * + * 99.01.25: now they also have a multiLine instance property. + * + */ + + +var r = new RegExp(); + +var e = new Array(); + +var t = new TestRegExp(); + +for ( p in r ) { e[e.length] = { property:p, value:r[p] }; t.addProperty( p, r[p]) }; + +new TestCase( SECTION, + "r = new RegExp(); e = new Array(); "+ + "for ( p in r ) { e[e.length] = { property:p, value:r[p] }; e.length", + 0, + e.length ); + +test(); + +function TestRegExp() { + this.addProperty = addProperty; +} +function addProperty(name, value) { + var pass = false; + + if ( eval("this."+name) != void 0 ) { + pass = true; + } else { + eval( "this."+ name+" = "+ false ); + } + + new TestCase( SECTION, + "Property: " + name +" already enumerated?", + false, + pass ); + + if ( gTestcases[ gTestcases.length-1].passed == false ) { + gTestcases[gTestcases.length-1].reason = "property already enumerated"; + + } + +} diff --git a/js/src/tests/ecma_2/RegExp/regress-001.js b/js/src/tests/ecma_2/RegExp/regress-001.js new file mode 100644 index 000000000..9282cd806 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/regress-001.js @@ -0,0 +1,45 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/regress-001.js + * ECMA Section: N/A + * Description: Regression test case: + * JS regexp anchoring on empty match bug + * http://bugzilla.mozilla.org/show_bug.cgi?id=2157 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/hex-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "JS regexp anchoring on empty match bug"; +var BUGNUMBER = "2157"; + +startTest(); + +AddRegExpCases( /a||b/.exec(''), + "/a||b/.exec('')", + 1, + [''] ); + +test(); + +function AddRegExpCases( regexp, str_regexp, length, matches_array ) { + + AddTestCase( + "( " + str_regexp + " ).length", + regexp.length, + regexp.length ); + + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + "( " + str_regexp + " )[" + matches +"]", + matches_array[matches], + regexp[matches] ); + } +} diff --git a/js/src/tests/ecma_2/RegExp/shell.js b/js/src/tests/ecma_2/RegExp/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/shell.js diff --git a/js/src/tests/ecma_2/RegExp/unicode-001.js b/js/src/tests/ecma_2/RegExp/unicode-001.js new file mode 100644 index 000000000..ab6fbd372 --- /dev/null +++ b/js/src/tests/ecma_2/RegExp/unicode-001.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/unicode-001.js + * ECMA Section: 15.7.3.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * Positive test cases for constructing a RegExp object + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/unicode-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "new RegExp( pattern, flags )"; + +startTest(); + +// These examples come from 15.7.1, UnicodeEscapeSequence + +AddRegExpCases( /\u0041/, "/\\u0041/", "A", "A", 1, 0, ["A"] ); +AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] ); +AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] ); +AddRegExpCases( /\u001g/, "/\\u001g/", "u001g", "u001g", 1, 0, ["u001g"] ); + +AddRegExpCases( /A/, "/A/", "\u0041", "\\u0041", 1, 0, ["A"] ); +AddRegExpCases( /A/, "/A/", "\u00412", "\\u00412", 1, 0, ["A"] ); +AddRegExpCases( /A2/, "/A2/", "\u00412", "\\u00412", 1, 0, ["A2"]); +AddRegExpCases( /A/, "/A/", "A2", "A2", 1, 0, ["A"] ); + +test(); + +function AddRegExpCases( + regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) { + + AddTestCase( + str_regexp + " .exec(" + str_pattern +").length", + length, + regexp.exec(pattern).length ); + + AddTestCase( + str_regexp + " .exec(" + str_pattern +").index", + index, + regexp.exec(pattern).index ); + + AddTestCase( + str_regexp + " .exec(" + str_pattern +").input", + pattern, + regexp.exec(pattern).input ); + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + str_regexp + " .exec(" + str_pattern +")[" + matches +"]", + matches_array[matches], + regexp.exec(pattern)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/Statements/browser.js b/js/src/tests/ecma_2/Statements/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Statements/browser.js diff --git a/js/src/tests/ecma_2/Statements/dowhile-001.js b/js/src/tests/ecma_2/Statements/dowhile-001.js new file mode 100644 index 000000000..d9a7a033d --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-001.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-001 + * ECMA Section: + * Description: do...while statements + * + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "dowhile-002"; +var VERSION = "ECMA_2"; +var TITLE = "do...while with a labeled continue statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +LabeledContinue( 0, 1 ); +LabeledContinue( 1, 1 ); +LabeledContinue( -1, 1 ); +LabeledContinue( 5, 5 ); + +test(); + +function LabeledContinue( limit, expect ) { + i = 0; +woohoo: + do { + i++; + continue woohoo; + } while ( i < limit ); + + new TestCase( + SECTION, + "do while ( " + i +" < " + limit +" )", + expect, + i ); +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-002.js b/js/src/tests/ecma_2/Statements/dowhile-002.js new file mode 100644 index 000000000..e25557e70 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-002.js @@ -0,0 +1,71 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-002 + * ECMA Section: + * Description: do...while statements + * + * Verify that code after a labeled break is not executed. Verify that + * a labeled break breaks you out of the whole labeled block, and not + * just the current iteration statement. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "dowhile-002"; +var VERSION = "ECMA_2"; +var TITLE = "do...while with a labeled continue statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +LabeledContinue( 0, 1 ); +LabeledContinue( 1, 1 ); +LabeledContinue( -1, 1 ); +LabeledContinue( 5, 5 ); + +test(); + +// The labeled statement contains statements after the labeled break. +// Verify that the statements after the break are not executed. + +function LabeledContinue( limit, expect ) { + i = 0; + result1 = "pass"; + result2 = "pass"; + +woohoo: { + do { + i++; + if ( ! (i < limit) ) { + break woohoo; + result1 = "fail: evaluated statement after a labeled break"; + } + } while ( true ); + + result2 = "failed: broke out of loop, but not out of labeled block"; + } + + new TestCase( + SECTION, + "do while ( " + i +" < " + limit +" )", + expect, + i ); + + new TestCase( + SECTION, + "breaking out of a do... while loop", + "pass", + result1 ); + + + new TestCase( + SECTION, + "breaking out of a labeled do...while loop", + "pass", + result2 ); +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-003.js b/js/src/tests/ecma_2/Statements/dowhile-003.js new file mode 100644 index 000000000..b482823e1 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-003.js @@ -0,0 +1,63 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-003 + * ECMA Section: + * Description: do...while statements + * + * Test do while, when the while expression is a JavaScript Number object. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "dowhile-003"; +var VERSION = "ECMA_2"; +var TITLE = "do...while with a labeled continue statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( new DoWhileObject( 1, 1, 0 )); +DoWhile( new DoWhileObject( 1000, 1000, 0 )); +DoWhile( new DoWhileObject( 1001, 1001, 0 )); +DoWhile( new DoWhileObject( 1002, 1001, 1 )); +DoWhile( new DoWhileObject( -1, 1001, -1002 )); + +test(); + +function DoWhileObject( value, iterations, endvalue ) { + this.value = value; + this.iterations = iterations; + this.endvalue = endvalue; +} + +function DoWhile( object ) { + var i = 0; + + do { + object.value = --object.value; + i++; + if ( i > 1000 ) + break; + } while( object.value ); + + new TestCase( + SECTION, + "loop iterations", + object.iterations, + i + ); + + new TestCase( + SECTION, + "object.value", + object.endvalue, + Number( object.value ) + ); + +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-004.js b/js/src/tests/ecma_2/Statements/dowhile-004.js new file mode 100644 index 000000000..90e376fde --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-004.js @@ -0,0 +1,67 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-004 + * ECMA Section: + * Description: do...while statements + * + * Test a labeled do...while. Break out of the loop with no label + * should break out of the loop, but not out of the label. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "dowhile-004"; +var VERSION = "ECMA_2"; +var TITLE = "do...while with a labeled continue statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( 0, 1 ); +DoWhile( 1, 1 ); +DoWhile( -1, 1 ); +DoWhile( 5, 5 ); + +test(); + +function DoWhile( limit, expect ) { + i = 0; + result1 = "pass"; + result2 = "failed: broke out of labeled statement unexpectedly"; + +foo: { + do { + i++; + if ( ! (i < limit) ) { + break; + result1 = "fail: evaluated statement after a labeled break"; + } + } while ( true ); + + result2 = "pass"; + } + + new TestCase( + SECTION, + "do while ( " + i +" < " + limit +" )", + expect, + i ); + + new TestCase( + SECTION, + "breaking out of a do... while loop", + "pass", + result1 ); + + + new TestCase( + SECTION, + "breaking out of a labeled do...while loop", + "pass", + result2 ); +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-005.js b/js/src/tests/ecma_2/Statements/dowhile-005.js new file mode 100644 index 000000000..3c339f493 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-005.js @@ -0,0 +1,73 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-005 + * ECMA Section: + * Description: do...while statements + * + * Test a labeled do...while. Break out of the loop with no label + * should break out of the loop, but not out of the label. + * + * Currently causes an infinite loop in the monkey. Uncomment the + * print statement below and it works OK. + * + * Author: christine@netscape.com + * Date: 26 August 1998 + */ +var SECTION = "dowhile-005"; +var VERSION = "ECMA_2"; +var TITLE = "do...while with a labeled continue statement"; +var BUGNUMBER = "316293"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +NestedLabel(); + + +test(); + +function NestedLabel() { + i = 0; + result1 = "pass"; + result2 = "fail: did not hit code after inner loop"; + result3 = "pass"; + +outer: { + do { + inner: { +// print( i ); + break inner; + result1 = "fail: did break out of inner label"; + } + result2 = "pass"; + break outer; + print(i); + } while ( i++ < 100 ); + + } + + result3 = "fail: did not break out of outer label"; + + new TestCase( + SECTION, + "number of loop iterations", + 0, + i ); + + new TestCase( + SECTION, + "break out of inner loop", + "pass", + result1 ); + + new TestCase( + SECTION, + "break out of outer loop", + "pass", + result2 ); +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-006.js b/js/src/tests/ecma_2/Statements/dowhile-006.js new file mode 100644 index 000000000..0a1aa701a --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-006.js @@ -0,0 +1,89 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-006 + * ECMA Section: + * Description: do...while statements + * + * A general do...while test. + * + * Author: christine@netscape.com + * Date: 26 August 1998 + */ +var SECTION = "dowhile-006"; +var VERSION = "ECMA_2"; +var TITLE = "do...while"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( new DoWhileObject( false, false, 10 ) ); +DoWhile( new DoWhileObject( true, false, 2 ) ); +DoWhile( new DoWhileObject( false, true, 3 ) ); +DoWhile( new DoWhileObject( true, true, 4 ) ); + +test(); + +function looping( object ) { + object.iterations--; + + if ( object.iterations <= 0 ) { + return false; + } else { + return true; + } +} +function DoWhileObject( breakOut, breakIn, iterations, loops ) { + this.iterations = iterations; + this.loops = loops; + this.breakOut = breakOut; + this.breakIn = breakIn; + this.looping = looping; +} +function DoWhile( object ) { + var result1 = false; + var result2 = false; + +outie: { + innie: { + do { + if ( object.breakOut ) + break outie; + + if ( object.breakIn ) + break innie; + + } while ( looping(object) ); + + // statements should be executed if: + // do...while exits normally + // do...while exits abruptly with no label + + result1 = true; + + } + +// statements should be executed if: +// do...while breaks out with label "innie" +// do...while exits normally +// do...while does not break out with "outie" + + result2 = true; + } + + new TestCase( + SECTION, + "hit code after loop in inner loop", + ( object.breakIn || object.breakOut ) ? false : true , + result1 ); + + new TestCase( + SECTION, + "hit code after loop in outer loop", + ( object.breakOut ) ? false : true, + result2 ); +} diff --git a/js/src/tests/ecma_2/Statements/dowhile-007.js b/js/src/tests/ecma_2/Statements/dowhile-007.js new file mode 100644 index 000000000..44adbcafd --- /dev/null +++ b/js/src/tests/ecma_2/Statements/dowhile-007.js @@ -0,0 +1,97 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: dowhile-007 + * ECMA Section: + * Description: do...while statements + * + * A general do...while test. + * + * Author: christine@netscape.com + * Date: 26 August 1998 + */ +var SECTION = "dowhile-007"; +var VERSION = "ECMA_2"; +var TITLE = "do...while"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( new DoWhileObject( false, false, false, false )); +DoWhile( new DoWhileObject( true, false, false, false )); +DoWhile( new DoWhileObject( true, true, false, false )); +DoWhile( new DoWhileObject( true, true, true, false )); +DoWhile( new DoWhileObject( true, true, true, true )); +DoWhile( new DoWhileObject( false, false, false, true )); +DoWhile( new DoWhileObject( false, false, true, true )); +DoWhile( new DoWhileObject( false, true, true, true )); +DoWhile( new DoWhileObject( false, false, true, false )); + +test(); + +function DoWhileObject( out1, out2, out3, in1 ) { + this.breakOutOne = out1; + this.breakOutTwo = out2; + this.breakOutThree = out3; + this.breakIn = in1; +} +function DoWhile( object ) { + result1 = false; + result2 = false; + result3 = false; + result4 = false; + +outie: + do { + if ( object.breakOutOne ) { + break outie; + } + result1 = true; + + innie: + do { + if ( object.breakOutTwo ) { + break outie; + } + result2 = true; + + if ( object.breakIn ) { + break innie; + } + result3 = true; + + } while ( false ); + if ( object.breakOutThree ) { + break outie; + } + result4 = true; + } while ( false ); + + new TestCase( + SECTION, + "break one: ", + (object.breakOutOne) ? false : true, + result1 ); + + new TestCase( + SECTION, + "break two: ", + (object.breakOutOne||object.breakOutTwo) ? false : true, + result2 ); + + new TestCase( + SECTION, + "break three: ", + (object.breakOutOne||object.breakOutTwo||object.breakIn) ? false : true, + result3 ); + + new TestCase( + SECTION, + "break four: ", + (object.breakOutOne||object.breakOutTwo||object.breakOutThree) ? false: true, + result4 ); +} diff --git a/js/src/tests/ecma_2/Statements/forin-001.js b/js/src/tests/ecma_2/Statements/forin-001.js new file mode 100644 index 000000000..215de6c4c --- /dev/null +++ b/js/src/tests/ecma_2/Statements/forin-001.js @@ -0,0 +1,297 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: forin-001.js + * ECMA Section: + * Description: The forin-001 statement + * + * Verify that the property name is assigned to the property on the left + * hand side of the for...in expression. + * + * Author: christine@netscape.com + * Date: 28 August 1998 + */ +var SECTION = "forin-001"; +var VERSION = "ECMA_2"; +var TITLE = "The for...in statement"; +var BUGNUMBER="330890"; +var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } ); +ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } ); +ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } ); + +// ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" }); +// ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" }); +ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" }); + +test(); + +/** + * Verify that the left side argument is evaluated with every iteration. + * Verify that the name of each property of the object is assigned to a + * a property. + * + */ +function ForIn_1( object ) { + PropertyArray = new Array(); + ValueArray = new Array(); + + for ( PropertyArray[PropertyArray.length] in object ) { + ValueArray[ValueArray.length] = + object[PropertyArray[PropertyArray.length-1]]; + } + + for ( var i = 0; i < PropertyArray.length; i++ ) { + new TestCase( + SECTION, + "object[" + PropertyArray[i] +"]", + object[PropertyArray[i]], + ValueArray[i] + ); + } + + new TestCase( + SECTION, + "object.length", + PropertyArray.length, + object.length ); +} + +/** + * Similar to ForIn_1, except it should increment the counter variable + * every time the left hand expression is evaluated. + */ +function ForIn_2( object ) { + PropertyArray = new Array(); + ValueArray = new Array(); + var i = 0; + + for ( PropertyArray[i++] in object ) { + ValueArray[ValueArray.length] = + object[PropertyArray[PropertyArray.length-1]]; + } + + for ( i = 0; i < PropertyArray.length; i++ ) { + new TestCase( + SECTION, + "object[" + PropertyArray[i] +"]", + object[PropertyArray[i]], + ValueArray[i] + ); + } + + new TestCase( + SECTION, + "object.length", + PropertyArray.length, + object.length ); +} + +/** + * Break out of a for...in loop + * + * + */ +function ForIn_3( object ) { + var checkBreak = "pass"; + var properties = new Array(); + var values = new Array(); + + for ( properties[properties.length] in object ) { + values[values.length] = object[properties[properties.length-1]]; + break; + checkBreak = "fail"; + } + + new TestCase( + SECTION, + "check break out of for...in", + "pass", + checkBreak ); + + new TestCase( + SECTION, + "properties.length", + 1, + properties.length ); + + new TestCase( + SECTION, + "object["+properties[0]+"]", + values[0], + object[properties[0]] ); +} + +/** + * Break out of a labeled for...in loop. + */ +function ForIn_4( object ) { + var result1 = 0; + var result2 = 0; + var result3 = 0; + var result4 = 0; + var i = 0; + var property = new Array(); + +butterbean: { + result1++; + + for ( property[i++] in object ) { + result2++; + break; + result4++; + } + result3++; + } + + new TestCase( + SECTION, + "verify labeled statement is only executed once", + true, + result1 == 1 ); + + new TestCase( + SECTION, + "verify statements in for loop are evaluated", + true, + result2 == i ); + + new TestCase( + SECTION, + "verify break out of labeled for...in loop", + true, + result4 == 0 ); + + new TestCase( + SECTION, + "verify break out of labeled block", + true, + result3 == 0 ); +} + +/** + * Labeled break out of a labeled for...in loop. + */ +function ForIn_5 (object) { + var result1 = 0; + var result2 = 0; + var result3 = 0; + var result4 = 0; + var i = 0; + var property = new Array(); + +bigredbird: { + result1++; + for ( property[i++] in object ) { + result2++; + break bigredbird; + result4++; + } + result3++; + } + + new TestCase( + SECTION, + "verify labeled statement is only executed once", + true, + result1 == 1 ); + + new TestCase( + SECTION, + "verify statements in for loop are evaluated", + true, + result2 == i ); + + new TestCase( + SECTION, + "verify break out of labeled for...in loop", + true, + result4 == 0 ); + + new TestCase( + SECTION, + "verify break out of labeled block", + true, + result3 == 0 ); +} + +/** + * Labeled continue from a labeled for...in loop + */ +function ForIn_7( object ) { + var result1 = 0; + var result2 = 0; + var result3 = 0; + var result4 = 0; + var i = 0; + var property = new Array(); + +bigredbird: + for ( property[i++] in object ) { + result2++; + continue bigredbird; + result4++; + } + + new TestCase( + SECTION, + "verify statements in for loop are evaluated", + true, + result2 == i ); + + new TestCase( + SECTION, + "verify break out of labeled for...in loop", + true, + result4 == 0 ); + + new TestCase( + SECTION, + "verify break out of labeled block", + true, + result3 == 1 ); +} + + +/** + * continue in a for...in loop + * + */ +function ForIn_8( object ) { + var checkBreak = "pass"; + var properties = new Array(); + var values = new Array(); + + for ( properties[properties.length] in object ) { + values[values.length] = object[properties[properties.length-1]]; + break; + checkBreak = "fail"; + } + + new TestCase( + SECTION, + "check break out of for...in", + "pass", + checkBreak ); + + new TestCase( + SECTION, + "properties.length", + 1, + properties.length ); + + new TestCase( + SECTION, + "object["+properties[0]+"]", + values[0], + object[properties[0]] ); +} + diff --git a/js/src/tests/ecma_2/Statements/forin-002.js b/js/src/tests/ecma_2/Statements/forin-002.js new file mode 100644 index 000000000..7d898d6bc --- /dev/null +++ b/js/src/tests/ecma_2/Statements/forin-002.js @@ -0,0 +1,77 @@ +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: forin-002.js + * ECMA Section: + * Description: The forin-001 statement + * + * Verify that the property name is assigned to the property on the left + * hand side of the for...in expression. + * + * Author: christine@netscape.com + * Date: 28 August 1998 + */ +var SECTION = "forin-002"; +var VERSION = "ECMA_2"; +var TITLE = "The for...in statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function MyObject( value ) { + this.value = value; + this.valueOf = new Function ( "return this.value" ); + this.toString = new Function ( "return this.value + \"\"" ); + this.toNumber = new Function ( "return this.value + 0" ); + this.toBoolean = new Function ( "return Boolean( this.value )" ); +} + +ForIn_1(this); +ForIn_2(this); + +ForIn_1(new MyObject(true)); +ForIn_2(new MyObject(new Boolean(true))); + +ForIn_2(3); + +test(); + +/** + * For ... In in a With Block + * + */ +function ForIn_1( object) { + with ( object ) { + for ( property in object ) { + new TestCase( + SECTION, + "with loop in a for...in loop. ("+object+")["+property +"] == "+ + "eval ( " + property +" )", + true, + object[property] == eval(property) ); + } + } +} + +/** + * With block in a For...In loop + * + */ +function ForIn_2(object) { + for ( property in object ) { + with ( object ) { + new TestCase( + SECTION, + "with loop in a for...in loop. ("+object+")["+property +"] == "+ + "eval ( " + property +" )", + true, + object[property] == eval(property) ); + } + } +} + diff --git a/js/src/tests/ecma_2/Statements/if-001.js b/js/src/tests/ecma_2/Statements/if-001.js new file mode 100644 index 000000000..ffc621a32 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/if-001.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: if-001.js + * ECMA Section: + * Description: The if statement + * + * Verify that assignment in the if expression is evaluated correctly. + * Verifies the fix for bug http://scopus/bugsplat/show_bug.cgi?id=148822. + * + * Author: christine@netscape.com + * Date: 28 August 1998 + */ +var SECTION = "for-001"; +var VERSION = "ECMA_2"; +var TITLE = "The if statement"; +var BUGNUMBER="148822"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var a = 0; +var b = 0; +var result = "passed"; + +if ( a = b ) { + result = "failed: a = b should return 0"; +} + +new TestCase( + SECTION, + "if ( a = b ), where a and b are both equal to 0", + "passed", + result ); + + +test(); + diff --git a/js/src/tests/ecma_2/Statements/label-001.js b/js/src/tests/ecma_2/Statements/label-001.js new file mode 100644 index 000000000..391732a2d --- /dev/null +++ b/js/src/tests/ecma_2/Statements/label-001.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: label-001.js + * ECMA Section: + * Description: Labeled statements + * + * Labeled break and continue within a for loop. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "label-003"; +var VERSION = "ECMA_2"; +var TITLE = "Labeled statements"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +LabelTest(0, 0); +LabelTest(1, 1) + LabelTest(-1, 1000); +LabelTest(false, 0); +LabelTest(true, 1); + +test(); + +function LabelTest( limit, expect) { +woo: for ( var result = 0; result < 1000; result++ ) { if (result == limit) { break woo; } else { continue woo; } }; + + new TestCase( + SECTION, + "break out of a labeled for loop: "+ limit, + expect, + result ); +} + diff --git a/js/src/tests/ecma_2/Statements/label-002.js b/js/src/tests/ecma_2/Statements/label-002.js new file mode 100644 index 000000000..1e2b63adc --- /dev/null +++ b/js/src/tests/ecma_2/Statements/label-002.js @@ -0,0 +1,56 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: label-002.js + * ECMA Section: + * Description: Labeled statements + * + * Labeled break and continue within a for-in loop. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "label-002"; +var VERSION = "ECMA_2"; +var TITLE = "Labeled statements"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +LabelTest( { p1:"hi,", p2:" norris" }, "hi, norris", " norrishi," ); +LabelTest( { 0:"zero", 1:"one" }, "zeroone", "onezero" ); + +LabelTest2( { p1:"hi,", p2:" norris" }, "hi,", " norris" ); +LabelTest2( { 0:"zero", 1:"one" }, "zero", "one" ); + +test(); + +function LabelTest( object, expect1, expect2 ) { + result = ""; + +yoohoo: { for ( property in object ) { result += object[property]; }; break yoohoo }; + + new TestCase( + SECTION, + "yoohoo: for ( property in object ) { result += object[property]; } break yoohoo }", + true, + result == expect1 || result == expect2 ); +} + +function LabelTest2( object, expect1, expect2 ) { + result = ""; + +yoohoo: { for ( property in object ) { result += object[property]; break yoohoo } }; ; + + new TestCase( + SECTION, + "yoohoo: for ( property in object ) { result += object[property]; break yoohoo }}", + true, + result == expect1 || result == expect2 ); +} + diff --git a/js/src/tests/ecma_2/Statements/label-003.js b/js/src/tests/ecma_2/Statements/label-003.js new file mode 100644 index 000000000..934732949 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/label-003.js @@ -0,0 +1,15 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// The colon for a labeled statement may be on a separate line. +var x; +label +: { + x = 1; + break label; + x = 2; +} +assertEq(x, 1); +reportCompare(0, 0, 'ok'); diff --git a/js/src/tests/ecma_2/Statements/shell.js b/js/src/tests/ecma_2/Statements/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/Statements/shell.js diff --git a/js/src/tests/ecma_2/Statements/switch-001.js b/js/src/tests/ecma_2/Statements/switch-001.js new file mode 100644 index 000000000..44e72985d --- /dev/null +++ b/js/src/tests/ecma_2/Statements/switch-001.js @@ -0,0 +1,65 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: switch-001.js + * ECMA Section: + * Description: The switch Statement + * + * A simple switch test with no abrupt completions. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + * + */ +var SECTION = "switch-001"; +var VERSION = "ECMA_2"; +var TITLE = "The switch statement"; + +var BUGNUMBER="315767"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +SwitchTest( 0, 126 ); +SwitchTest( 1, 124 ); +SwitchTest( 2, 120 ); +SwitchTest( 3, 112 ); +SwitchTest( 4, 64 ); +SwitchTest( 5, 96 ); +SwitchTest( true, 96 ); +SwitchTest( false, 96 ); +SwitchTest( null, 96 ); +SwitchTest( void 0, 96 ); +SwitchTest( "0", 96 ); + +test(); + +function SwitchTest( input, expect ) { + var result = 0; + + switch ( input ) { + case 0: + result += 2; + case 1: + result += 4; + case 2: + result += 8; + case 3: + result += 16; + default: + result += 32; + case 4: + result +=64; + } + + new TestCase( + SECTION, + "switch with no breaks, case expressions are numbers. input is "+ + input, + expect, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/switch-002.js b/js/src/tests/ecma_2/Statements/switch-002.js new file mode 100644 index 000000000..3e08630be --- /dev/null +++ b/js/src/tests/ecma_2/Statements/switch-002.js @@ -0,0 +1,63 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: switch-002.js + * ECMA Section: + * Description: The switch Statement + * + * A simple switch test with no abrupt completions. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + * + */ +var SECTION = "switch-002"; +var VERSION = "ECMA_2"; +var TITLE = "The switch statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +SwitchTest( 0, 6 ); +SwitchTest( 1, 4 ); +SwitchTest( 2, 56 ); +SwitchTest( 3, 48 ); +SwitchTest( 4, 64 ); +SwitchTest( true, 32 ); +SwitchTest( false, 32 ); +SwitchTest( null, 32 ); +SwitchTest( void 0, 32 ); +SwitchTest( "0", 32 ); + +test(); + +function SwitchTest( input, expect ) { + var result = 0; + + switch ( input ) { + case 0: + result += 2; + case 1: + result += 4; + break; + case 2: + result += 8; + case 3: + result += 16; + default: + result += 32; + break; + case 4: + result += 64; + } + + new TestCase( + SECTION, + "switch with no breaks: input is " + input, + expect, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/switch-003.js b/js/src/tests/ecma_2/Statements/switch-003.js new file mode 100644 index 000000000..5ceaade69 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/switch-003.js @@ -0,0 +1,57 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: switch-003.js + * ECMA Section: + * Description: The switch Statement + * + * Attempt to verify that case statements are evaluated in source order + * + * Author: christine@netscape.com + * Date: 11 August 1998 + * + */ +var SECTION = "switch-003"; +var VERSION = "ECMA_2"; +var TITLE = "The switch statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +SwitchTest( "a", "abc" ); +SwitchTest( "b", "bc" ); +SwitchTest( "c", "c" ); +SwitchTest( "d", "*abc" ); +SwitchTest( "v", "*abc" ); +SwitchTest( "w", "w*abc" ); +SwitchTest( "x", "xw*abc" ); +SwitchTest( "y", "yxw*abc" ); +SwitchTest( "z", "zyxw*abc" ); +// SwitchTest( new java.lang.String("z"), "*abc" ); + +test(); + +function SwitchTest( input, expect ) { + var result = ""; + + switch ( input ) { + case "z": result += "z"; + case "y": result += "y"; + case "x": result += "x"; + case "w": result += "w"; + default: result += "*"; + case "a": result += "a"; + case "b": result += "b"; + case "c": result += "c"; + } + + new TestCase( + SECTION, + "switch with no breaks: input is " + input, + expect, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/switch-004.js b/js/src/tests/ecma_2/Statements/switch-004.js new file mode 100644 index 000000000..0572874a6 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/switch-004.js @@ -0,0 +1,94 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: switch-003.js + * ECMA Section: + * Description: The switch Statement + * + * This uses variables and objects as case expressions in switch statements. + * This verifies a bunch of bugs: + * + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954 + * + * Author: christine@netscape.com + * Date: 11 August 1998 + * + */ +var SECTION = "switch-003"; +var VERSION = "ECMA_2"; +var TITLE = "The switch statement"; +var BUGNUMBER= "315988"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +ONE = new Number(1); +ZERO = new Number(0); +var A = new String("A"); +var B = new String("B"); +TRUE = new Boolean( true ); +FALSE = new Boolean( false ); +UNDEFINED = void 0; +NULL = null; + +SwitchTest( ZERO, "ZERO" ); +SwitchTest( NULL, "NULL" ); +SwitchTest( UNDEFINED, "UNDEFINED" ); +SwitchTest( FALSE, "FALSE" ); +SwitchTest( false, "false" ); +SwitchTest( 0, "0" ); + +SwitchTest ( TRUE, "TRUE" ); +SwitchTest( 1, "1" ); +SwitchTest( ONE, "ONE" ); +SwitchTest( true, "true" ); + +SwitchTest( "a", "a" ); +SwitchTest( A, "A" ); +SwitchTest( "b", "b" ); +SwitchTest( B, "B" ); + +SwitchTest( new Boolean( true ), "default" ); +SwitchTest( new Boolean(false ), "default" ); +SwitchTest( new String( "A" ), "default" ); +SwitchTest( new Number( 0 ), "default" ); + +test(); + +function SwitchTest( input, expect ) { + var result = ""; + + switch ( input ) { + default: result += "default"; break; + case "a": result += "a"; break; + case "b": result += "b"; break; + case A: result += "A"; break; + case B: result += "B"; break; + case new Boolean(true): result += "new TRUE"; break; + case new Boolean(false): result += "new FALSE"; break; + case NULL: result += "NULL"; break; + case UNDEFINED: result += "UNDEFINED"; break; + case true: result += "true"; break; + case false: result += "false"; break; + case TRUE: result += "TRUE"; break; + case FALSE: result += "FALSE"; break; + case 0: result += "0"; break; + case 1: result += "1"; break; + case new Number(0) : result += "new ZERO"; break; + case new Number(1) : result += "new ONE"; break; + case ONE: result += "ONE"; break; + case ZERO: result += "ZERO"; break; + } + + new TestCase( + SECTION, + "switch with no breaks: input is " + input, + expect, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/try-001.js b/js/src/tests/ecma_2/Statements/try-001.js new file mode 100644 index 000000000..931837cd3 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-001.js @@ -0,0 +1,83 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-001.js + * ECMA Section: + * Description: The try statement + * + * This test contains try, catch, and finally blocks. An exception is + * sometimes thrown by a function called from within the try block. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = ""; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor"; + +TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE ); +TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE ); +TryNewJavaInteger( 0, 0 ); +TryNewJavaInteger( -1, -1 ); +TryNewJavaInteger( 1, 1 ); +TryNewJavaInteger( Infinity, Infinity ); + +test(); + +/** + * Check to see if the input is valid for java.lang.Integer. If it is + * not valid, throw INVALID_JAVA_INTEGER_VALUE. If input is valid, + * return Number( v ) + * + */ + +function newJavaInteger( v ) { + value = Number( v ); + if ( Math.floor(value) != value || isNaN(value) ) { + throw ( INVALID_JAVA_INTEGER_VALUE ); + } else { + return value; + } +} + +/** + * Call newJavaInteger( value ) from within a try block. Catch any + * exception, and store it in result. Verify that we got the right + * return value from newJavaInteger in cases in which we do not expect + * exceptions, and that we got the exception in cases where an exception + * was expected. + */ +function TryNewJavaInteger( value, expect ) { + var finalTest = false; + + try { + result = newJavaInteger( value ); + } catch ( e ) { + result = String( e ); + } finally { + finalTest = true; + } + new TestCase( + SECTION, + "newJavaValue( " + value +" )", + expect, + result); + + new TestCase( + SECTION, + "newJavaValue( " + value +" ) hit finally block", + true, + finalTest); + +} + diff --git a/js/src/tests/ecma_2/Statements/try-003.js b/js/src/tests/ecma_2/Statements/try-003.js new file mode 100644 index 000000000..9244fcb5d --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-003.js @@ -0,0 +1,82 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-003.js + * ECMA Section: + * Description: The try statement + * + * This test has a try with no catch, and a finally. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-003"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; +var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=313585"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// Tests start here. + +TrySomething( "x = \"hi\"", false ); +TrySomething( "throw \"boo\"", true ); +TrySomething( "throw 3", true ); + +test(); + +/** + * This function contains a try block with no catch block, + * but it does have a finally block. Try to evaluate expressions + * that do and do not throw exceptions. + */ + +function TrySomething( expression, throwing ) { + innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; + if (throwing) { + outerCatch = "FAILED: NO EXCEPTION CAUGHT"; + } else { + outerCatch = "PASS"; + } + outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; + + try { + try { + eval( expression ); + } finally { + innerFinally = "PASS"; + } + } catch ( e ) { + if (throwing) { + outerCatch = "PASS"; + } else { + outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; + } + } finally { + outerFinally = "PASS"; + } + + + new TestCase( + SECTION, + "eval( " + expression +" )", + "PASS", + innerFinally ); + new TestCase( + SECTION, + "eval( " + expression +" )", + "PASS", + outerCatch ); + new TestCase( + SECTION, + "eval( " + expression +" )", + "PASS", + outerFinally ); + + +} diff --git a/js/src/tests/ecma_2/Statements/try-004.js b/js/src/tests/ecma_2/Statements/try-004.js new file mode 100644 index 000000000..dbc554559 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-004.js @@ -0,0 +1,54 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-004.js + * ECMA Section: + * Description: The try statement + * + * This test has a try with one catch block but no finally. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-004"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +TryToCatch( "Math.PI", Math.PI ); +TryToCatch( "Thrower(5)", "Caught 5" ); +TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" ); + +test(); + +function Thrower( v ) { + throw "Caught " + v; +} + +/** + * Evaluate a string. Catch any exceptions thrown. If no exception is + * expected, verify the result of the evaluation. If an exception is + * expected, verify that we got the right exception. + */ + +function TryToCatch( value, expect ) { + try { + result = eval( value ); + } catch ( e ) { + result = e; + } + + new TestCase( + SECTION, + "eval( " + value +" )", + expect, + result ); +} + + diff --git a/js/src/tests/ecma_2/Statements/try-005.js b/js/src/tests/ecma_2/Statements/try-005.js new file mode 100644 index 000000000..b50c5bf53 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-005.js @@ -0,0 +1,57 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-005.js + * ECMA Section: + * Description: The try statement + * + * This test has a try with one catch block but no finally. Same + * as try-004, but the eval statement is called from a function, not + * directly from within the try block. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-005"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +TryToCatch( "Math.PI", Math.PI ); +TryToCatch( "Thrower(5)", "Caught 5" ); +TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" ); + +test(); + +function Thrower( v ) { + throw "Caught " + v; +} +function Eval( v ) { + return eval( v ); +} + +/** + * Evaluate a string. Catch any exceptions thrown. If no exception is + * expected, verify the result of the evaluation. If an exception is + * expected, verify that we got the right exception. + */ + +function TryToCatch( value, expect ) { + try { + result = Eval( value ); + } catch ( e ) { + result = e; + } + + new TestCase( + SECTION, + "eval( " + value +" )", + expect, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/try-006.js b/js/src/tests/ecma_2/Statements/try-006.js new file mode 100644 index 000000000..0a85200a1 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-006.js @@ -0,0 +1,87 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-006.js + * ECMA Section: + * Description: The try statement + * + * Throw an exception from within a With block in a try block. Verify + * that any expected exceptions are caught. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-006"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +/** + * This is the "check" function for test objects that will + * throw an exception. + */ +function throwException() { + throw EXCEPTION_STRING +": " + this.valueOf(); +} +var EXCEPTION_STRING = "Exception thrown:"; + +/** + * This is the "check" function for test objects that do not + * throw an exception + */ +function noException() { + return this.valueOf(); +} + +/** + * Add test cases here + */ +TryWith( new TryObject( "hello", throwException, true )); +TryWith( new TryObject( "hola", noException, false )); + +/** + * Run the test. + */ + +test(); + +/** + * This is the object that will be the "this" in a with block. + */ +function TryObject( value, fun, exception ) { + this.value = value; + this.exception = exception; + + this.valueOf = new Function ( "return this.value" ); + this.check = fun; +} + +/** + * This function has the try block that has a with block within it. + * Test cases are added in this function. Within the with block, the + * object's "check" function is called. If the test object's exception + * property is true, we expect the result to be the exception value. + * If exception is false, then we expect the result to be the value of + * the object. + */ +function TryWith( object ) { + try { + with ( object ) { + result = check(); + } + } catch ( e ) { + result = e; + } + + new TestCase( + SECTION, + "TryWith( " + object.value +" )", + (object.exception ? EXCEPTION_STRING +": " + object.valueOf() : object.valueOf()), + result ); +} diff --git a/js/src/tests/ecma_2/Statements/try-007.js b/js/src/tests/ecma_2/Statements/try-007.js new file mode 100644 index 000000000..93e08a0a1 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-007.js @@ -0,0 +1,92 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-007.js + * ECMA Section: + * Description: The try statement + * + * This test has a for-in statement within a try block. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-007"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement: for-in"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +/** + * This is the "check" function for test objects that will + * throw an exception. + */ +function throwException() { + throw EXCEPTION_STRING +": " + this.valueOf(); +} +var EXCEPTION_STRING = "Exception thrown:"; + +/** + * This is the "check" function for test objects that do not + * throw an exception + */ +function noException() { + return this.valueOf(); +} + +/** + * Add test cases here + */ +TryForIn( new TryObject( "hello", throwException, true )); +TryForIn( new TryObject( "hola", noException, false )); + +/** + * Run the test. + */ + +test(); + +/** + * This is the object that will be the "this" in a with block. + * The check function is either throwException() or noException(). + * See above. + * + */ +function TryObject( value, fun, exception ) { + this.value = value; + this.exception = exception; + + this.check = fun; + this.valueOf = function () { return this.value; } +} + +/** + * This function has a for-in statement within a try block. Test cases + * are added after the try-catch-finally statement. Within the for-in + * block, call a function that can throw an exception. Verify that any + * exceptions are properly caught. + */ + +function TryForIn( object ) { + try { + for ( p in object ) { + if ( typeof object[p] == "function" ) { + result = object[p](); + } + } + } catch ( e ) { + result = e; + } + + new TestCase( + SECTION, + "TryForIn( " + object+ " )", + (object.exception ? EXCEPTION_STRING +": " + object.value : object.value), + result ); + +} diff --git a/js/src/tests/ecma_2/Statements/try-008.js b/js/src/tests/ecma_2/Statements/try-008.js new file mode 100644 index 000000000..d47ced0ae --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-008.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-008.js + * ECMA Section: + * Description: The try statement + * + * This test has a try block in a constructor. + * + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-008"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement: try in a constructor"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function Integer( value, exception ) { + try { + this.value = checkValue( value ); + } catch ( e ) { + this.value = e.toString(); + } + + new TestCase( + SECTION, + "Integer( " + value +" )", + (exception ? INVALID_INTEGER_VALUE +": " + value : this.value), + this.value ); +} + +var INVALID_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor"; + +function checkValue( value ) { + if ( Math.floor(value) != value || isNaN(value) ) { + throw ( INVALID_INTEGER_VALUE +": " + value ); + } else { + return value; + } +} + +// add test cases + +new Integer( 3, false ); +new Integer( NaN, true ); +new Integer( 0, false ); +new Integer( Infinity, false ); +new Integer( -2.12, true ); +new Integer( Math.LN2, true ); + + +test(); diff --git a/js/src/tests/ecma_2/Statements/try-009.js b/js/src/tests/ecma_2/Statements/try-009.js new file mode 100644 index 000000000..d3e0ebaa2 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-009.js @@ -0,0 +1,66 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-009.js + * ECMA Section: + * Description: The try statement + * + * This test has a try block within a while block. Verify that an exception + * breaks out of the while. I don't really know why this is an interesting + * test case but Mike Shaver had two of these so what the hey. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-009"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement: try in a while block"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var EXCEPTION_STRING = "Exception thrown: "; +var NO_EXCEPTION_STRING = "No exception thrown: "; + + +TryInWhile( new TryObject( "hello", ThrowException, true ) ); +TryInWhile( new TryObject( "aloha", NoException, false )); + +test(); + +function TryObject( value, throwFunction, result ) { + this.value = value; + this.thrower = throwFunction; + this.result = result; +} +function ThrowException() { + throw EXCEPTION_STRING + this.value; +} +function NoException() { + return NO_EXCEPTION_STRING + this.value; +} +function TryInWhile( object ) { + result = null; + while ( true ) { + try { + object.thrower(); + result = NO_EXCEPTION_STRING + object.value; + break; + } catch ( e ) { + result = e; + break; + } + } + + new TestCase( + SECTION, + "( "+ object +".thrower() )", + (object.result + ? EXCEPTION_STRING + object.value : + NO_EXCEPTION_STRING + object.value), + result ); +} diff --git a/js/src/tests/ecma_2/Statements/try-010.js b/js/src/tests/ecma_2/Statements/try-010.js new file mode 100644 index 000000000..5ee472c3b --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-010.js @@ -0,0 +1,73 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-010.js + * ECMA Section: + * Description: The try statement + * + * This has a try block nested in the try block. Verify that the + * exception is caught by the right try block, and all finally blocks + * are executed. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-010"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement: try in a tryblock"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var EXCEPTION_STRING = "Exception thrown: "; +var NO_EXCEPTION_STRING = "No exception thrown: "; + + +NestedTry( new TryObject( "No Exceptions Thrown", NoException, NoException, 43 ) ); +NestedTry( new TryObject( "Throw Exception in Outer Try", ThrowException, NoException, 48 )); +NestedTry( new TryObject( "Throw Exception in Inner Try", NoException, ThrowException, 45 )); +NestedTry( new TryObject( "Throw Exception in Both Trys", ThrowException, ThrowException, 48 )); + +test(); + +function TryObject( description, tryOne, tryTwo, result ) { + this.description = description; + this.tryOne = tryOne; + this.tryTwo = tryTwo; + this.result = result; +} +function ThrowException() { + throw EXCEPTION_STRING + this.value; +} +function NoException() { + return NO_EXCEPTION_STRING + this.value; +} +function NestedTry( object ) { + result = 0; + try { + object.tryOne(); + result += 1; + try { + object.tryTwo(); + result += 2; + } catch ( e ) { + result +=4; + } finally { + result += 8; + } + } catch ( e ) { + result += 16; + } finally { + result += 32; + } + + new TestCase( + SECTION, + object.description, + object.result, + result ); +} diff --git a/js/src/tests/ecma_2/Statements/try-012.js b/js/src/tests/ecma_2/Statements/try-012.js new file mode 100644 index 000000000..3ee7d1026 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/try-012.js @@ -0,0 +1,95 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: try-012.js + * ECMA Section: + * Description: The try statement + * + * This test has a try with no catch, and a finally. This is like try-003, + * but throws from a finally block, not the try block. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "try-012"; +var VERSION = "ECMA_2"; +var TITLE = "The try statement"; +var BUGNUMBER="336872"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// Tests start here. + +TrySomething( "x = \"hi\"", true ); +TrySomething( "throw \"boo\"", true ); +TrySomething( "throw 3", true ); + +test(); + +/** + * This function contains a try block with no catch block, + * but it does have a finally block. Try to evaluate expressions + * that do and do not throw exceptions. + * + * The productioni TryStatement Block Finally is evaluated as follows: + * 1. Evaluate Block + * 2. Evaluate Finally + * 3. If Result(2).type is normal return result 1 (in the test case, result 1 has + * the completion type throw) + * 4. return result 2 (does not get hit in this case) + * + */ + +function TrySomething( expression, throwing ) { + innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; + if (throwing) { + outerCatch = "FAILED: NO EXCEPTION CAUGHT"; + } else { + outerCatch = "PASS"; + } + outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; + + + // If the inner finally does not throw an exception, the result + // of the try block should be returned. (Type of inner return + // value should be throw if finally executes correctly + + try { + try { + throw 0; + } finally { + innerFinally = "PASS"; + eval( expression ); + } + } catch ( e ) { + if (throwing) { + outerCatch = "PASS"; + } else { + outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; + } + } finally { + outerFinally = "PASS"; + } + + + new TestCase( + SECTION, + "eval( " + expression +" ): evaluated inner finally block", + "PASS", + innerFinally ); + new TestCase( + SECTION, + "eval( " + expression +" ): evaluated outer catch block ", + "PASS", + outerCatch ); + new TestCase( + SECTION, + "eval( " + expression +" ): evaluated outer finally block", + "PASS", + outerFinally ); +} diff --git a/js/src/tests/ecma_2/Statements/while-001.js b/js/src/tests/ecma_2/Statements/while-001.js new file mode 100644 index 000000000..88fd8dfe8 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/while-001.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: while-001 + * ECMA Section: + * Description: while statement + * + * Verify that the while statement is not executed if the while expression is + * false + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "while-001"; +var VERSION = "ECMA_2"; +var TITLE = "while statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile(); +test(); + +function DoWhile() { + result = "pass"; + + while (false) { + result = "fail"; + break; + } + + new TestCase( + SECTION, + "while statement: don't evaluate statement is expression is false", + "pass", + result ); + +} diff --git a/js/src/tests/ecma_2/Statements/while-002.js b/js/src/tests/ecma_2/Statements/while-002.js new file mode 100644 index 000000000..a3c315bf2 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/while-002.js @@ -0,0 +1,86 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: while-002 + * ECMA Section: + * Description: while statement + * + * Verify that the while statement is not executed if the while expression is + * false + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "while-002"; +var VERSION = "ECMA_2"; +var TITLE = "while statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( new DoWhileObject( + "while expression is null", + null, + "result = \"fail: should not have evaluated statements in while block;break" + ) ); + +DoWhile( new DoWhileObject( + "while expression is undefined", + void 0, + "result = \"fail: should not have evaluated statements in while block; break" + )); + +DoWhile( new DoWhileObject( + "while expression is 0", + 0, + "result = \"fail: should not have evaluated statements in while block; break;" + )); + +DoWhile( new DoWhileObject( + "while expression is eval(\"\")", + eval(""), + "result = \"fail: should not have evaluated statements in while block; break" + )); + +DoWhile( new DoWhileObject( + "while expression is NaN", + NaN, + "result = \"fail: should not have evaluated statements in while block; break" + )); + +test(); + +function DoWhileObject( d, e, s ) { + this.description = d; + this.whileExpression = e; + this.statements = s; +} + +function DoWhile( object ) { + result = "pass"; + + while ( expression = object.whileExpression ) { + eval( object.statements ); + } + + // verify that the while expression was evaluated + + new TestCase( + SECTION, + "verify that while expression was evaluated (should be "+ + object.whileExpression +")", + "pass", + (object.whileExpression == expression || + ( isNaN(object.whileExpression) && isNaN(expression) ) + ) ? "pass" : "fail" ); + + new TestCase( + SECTION, + object.description, + "pass", + result ); +} diff --git a/js/src/tests/ecma_2/Statements/while-003.js b/js/src/tests/ecma_2/Statements/while-003.js new file mode 100644 index 000000000..b47d09a7a --- /dev/null +++ b/js/src/tests/ecma_2/Statements/while-003.js @@ -0,0 +1,87 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: while-003 + * ECMA Section: + * Description: while statement + * + * The while expression evaluates to true, Statement returns abrupt completion. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "while-003"; +var VERSION = "ECMA_2"; +var TITLE = "while statement"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile( new DoWhileObject( + "while expression is true", + true, + "result = \"pass\";" )); + +DoWhile( new DoWhileObject( + "while expression is 1", + 1, + "result = \"pass\";" )); + +DoWhile( new DoWhileObject( + "while expression is new Boolean(false)", + new Boolean(false), + "result = \"pass\";" )); + +DoWhile( new DoWhileObject( + "while expression is new Object()", + new Object(), + "result = \"pass\";" )); + +DoWhile( new DoWhileObject( + "while expression is \"hi\"", + "hi", + "result = \"pass\";" )); +/* + DoWhile( new DoWhileObject( + "while expression has a continue in it", + "true", + "if ( i == void 0 ) i = 0; result=\"pass\"; if ( ++i == 1 ) {continue;} else {break;} result=\"fail\";" + )); +*/ +test(); + +function DoWhileObject( d, e, s ) { + this.description = d; + this.whileExpression = e; + this.statements = s; +} + +function DoWhile( object ) { + result = "fail: statements in while block were not evaluated"; + + while ( expression = object.whileExpression ) { + eval( object.statements ); + break; + } + + // verify that the while expression was evaluated + + new TestCase( + SECTION, + "verify that while expression was evaluated (should be "+ + object.whileExpression +")", + "pass", + (object.whileExpression == expression || + ( isNaN(object.whileExpression) && isNaN(expression) ) + ) ? "pass" : "fail" ); + + new TestCase( + SECTION, + object.description, + "pass", + result ); +} diff --git a/js/src/tests/ecma_2/Statements/while-004.js b/js/src/tests/ecma_2/Statements/while-004.js new file mode 100644 index 000000000..393e680e5 --- /dev/null +++ b/js/src/tests/ecma_2/Statements/while-004.js @@ -0,0 +1,217 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: while-004 + * ECMA Section: + * Description: while statement + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "while-004"; +var VERSION = "ECMA_2"; +var TITLE = "while statement"; +var BUGNUMBER="316725"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +DoWhile_1(); +DoWhile_2(); +DoWhile_3(); +DoWhile_4(); +DoWhile_5(); + +test(); + +/** + * Break out of a while by calling return. + * + * Tests: 12.6.2 step 6. + */ +function dowhile() { + result = "pass"; + + while (true) { + return result; + result = "fail: hit code after return statement"; + break; + } +} + +function DoWhile_1() { + description = "return statement in a while block"; + + result = dowhile(); + + new TestCase( + SECTION, + "DoWhile_1" + description, + "pass", + result ); +} + +/** + * While with a labeled continue statement. Verify that statements + * after the continue statement are not evaluated. + * + * Tests: 12.6.2 step 8. + * + */ +function DoWhile_2() { + var description = "while with a labeled continue statement"; + var result1 = "pass"; + var result2 = "fail: did not execute code after loop, but inside label"; + var i = 0; + var j = 0; + +theloop: + while( i++ < 10 ) { + j++; + continue theloop; + result1 = "failed: hit code after continue statement"; + } + result2 = "pass"; + + new TestCase( + SECTION, + "DoWhile_2: " +description + " - code inside the loop, before the continue should be executed ("+j+")", + true, + j == 10 ); + + new TestCase( + SECTION, + "DoWhile_2: " +description +" - code after labeled continue should not be executed", + "pass", + result1 ); + + new TestCase( + SECTION, + "DoWhile_2: " +description +" - code after loop but inside label should be executed", + "pass", + result2 ); +} + +/** + * While with a labeled break. + * + */ +function DoWhile_3() { + var description = "while with a labeled break statement"; + var result1 = "pass"; + var result2 = "pass"; + var result3 = "fail: did not get to code after label"; + +woohoo: { + while( true ) { + break woohoo; + result1 = "fail: got to code after a break"; + } + result2 = "fail: got to code outside of loop but inside label"; + } + + result3 = "pass"; + + new TestCase( + SECTION, + "DoWhile_3: " +description +" - verify break out of loop", + "pass", + result1 ); + + + new TestCase( + SECTION, + "DoWhile_3: " +description +" - verify break out of label", + "pass", + result2 ); + + new TestCase( + SECTION, + "DoWhile_3: " +description + " - verify correct exit from label", + "pass", + result3 ); +} + + +/** + * Labled while with an unlabeled break + * + */ +function DoWhile_4() { + var description = "labeled while with an unlabeled break"; + var result1 = "pass"; + var result2 = "pass"; + var result3 = "fail: did not evaluate statement after label"; + +woohooboy: { + while( true ) { + break woohooboy; + result1 = "fail: got to code after the break"; + } + result2 = "fail: broke out of while, but not out of label"; + } + result3 = "pass"; + + new TestCase( + SECTION, + "DoWhile_4: " +description +" - verify break out of while loop", + "pass", + result1 ); + + new TestCase( + SECTION, + "DoWhile_4: " +description + " - verify break out of label", + "pass", + result2 ); + + new TestCase( + SECTION, + "DoWhile_4: " +description +" - verify that statements after label are evaluated", + "pass", + result3 ); +} + +/** + * in this case, should behave the same way as + * + * + */ +function DoWhile_5() { + var description = "while with a labeled continue statement"; + var result1 = "pass"; + var result2 = "fail: did not execute code after loop, but inside label"; + var i = 0; + var j = 0; + +theloop: { + j++; + while( i++ < 10 ) { + continue; + result1 = "failed: hit code after continue statement"; + } + result2 = "pass"; + } + + new TestCase( + SECTION, + "DoWhile_5: " +description + " - continue should not execute statements above the loop", + true, + ( j == 1 ) ); + + new TestCase( + SECTION, + "DoWhile_5: " +description +" - code after labeled continue should not be executed", + "pass", + result1 ); + + new TestCase( + SECTION, + "DoWhile_5: " +description +" - code after loop but inside label should be executed", + "pass", + result2 ); +} + diff --git a/js/src/tests/ecma_2/String/browser.js b/js/src/tests/ecma_2/String/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/String/browser.js diff --git a/js/src/tests/ecma_2/String/match-001.js b/js/src/tests/ecma_2/String/match-001.js new file mode 100644 index 000000000..ab6082a1a --- /dev/null +++ b/js/src/tests/ecma_2/String/match-001.js @@ -0,0 +1,106 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/match-001.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * String.match( regexp ) + * + * If regexp is not an object of type RegExp, it is replaced with result + * of the expression new RegExp(regexp). Let string denote the result of + * converting the this value to a string. If regexp.global is false, + * return the result obtained by invoking RegExp.prototype.exec (see + * section 15.7.5.3) on regexp with string as parameter. + * + * Otherwise, set the regexp.lastIndex property to 0 and invoke + * RegExp.prototype.exec repeatedly until there is no match. If there is a + * match with an empty string (in other words, if the value of + * regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1. + * The value returned is an array with the properties 0 through n-1 + * corresponding to the first element of the result of each matching + * invocation of RegExp.prototype.exec. + * + * Note that the match function is intentionally generic; it does not + * require that its this value be a string object. Therefore, it can be + * transferred to other kinds of objects for use as a method. + */ + +var SECTION = "String/match-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.match( regexp )"; + +startTest(); + +// the regexp argument is not a RegExp object +// this is not a string object + +// cases in which the regexp global property is false + +AddRegExpCases( 3, "3", "1234567890", 1, 2, ["3"] ); + +// cases in which the regexp object global property is true + +AddGlobalRegExpCases( /34/g, "/34/g", "343443444", 3, ["34", "34", "34"] ); +AddGlobalRegExpCases( /\d{1}/g, "/d{1}/g", "123456abcde7890", 10, + ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] ); + +AddGlobalRegExpCases( /\d{2}/g, "/d{2}/g", "123456abcde7890", 5, + ["12", "34", "56", "78", "90"] ); + +AddGlobalRegExpCases( /\D{2}/g, "/d{2}/g", "123456abcde7890", 2, + ["ab", "cd"] ); + +test(); + + +function AddRegExpCases( + regexp, str_regexp, string, length, index, matches_array ) { + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + length, + string.match(regexp).length ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").index", + index, + string.match(regexp).index ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").input", + string, + string.match(regexp).input ); + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} + +function AddGlobalRegExpCases( + regexp, str_regexp, string, length, matches_array ) { + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + length, + string.match(regexp).length ); + + for ( var matches = 0; matches < matches_array.length; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/String/match-002.js b/js/src/tests/ecma_2/String/match-002.js new file mode 100644 index 000000000..21b832501 --- /dev/null +++ b/js/src/tests/ecma_2/String/match-002.js @@ -0,0 +1,174 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/match-002.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * String.match( regexp ) + * + * If regexp is not an object of type RegExp, it is replaced with result + * of the expression new RegExp(regexp). Let string denote the result of + * converting the this value to a string. If regexp.global is false, + * return the result obtained by invoking RegExp.prototype.exec (see + * section 15.7.5.3) on regexp with string as parameter. + * + * Otherwise, set the regexp.lastIndex property to 0 and invoke + * RegExp.prototype.exec repeatedly until there is no match. If there is a + * match with an empty string (in other words, if the value of + * regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1. + * The value returned is an array with the properties 0 through n-1 + * corresponding to the first element of the result of each matching + * invocation of RegExp.prototype.exec. + * + * Note that the match function is intentionally generic; it does not + * require that its this value be a string object. Therefore, it can be + * transferred to other kinds of objects for use as a method. + * + * This file tests cases in which regexp.global is false. Therefore, + * results should behave as regexp.exec with string passed as a parameter. + * + */ + +var SECTION = "String/match-002.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.match( regexp )"; + +startTest(); + +// the regexp argument is not a RegExp object +// this is not a string object + +AddRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/, + "/([\d]{5})([-\ ]?[\d]{4})?$/", + "Boston, Mass. 02134", + 14, + ["02134", "02134", undefined]); + +AddGlobalRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/g, + "/([\d]{5})([-\ ]?[\d]{4})?$/g", + "Boston, Mass. 02134", + ["02134"]); + +// set the value of lastIndex +re = /([\d]{5})([-\ ]?[\d]{4})?$/; +re.lastIndex = 0; + +s = "Boston, MA 02134"; + +AddRegExpCases( re, + "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex =0", + s, + s.lastIndexOf("0"), + ["02134", "02134", undefined]); + + +re.lastIndex = s.length; + +AddRegExpCases( re, + "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + + s.length, + s, + s.lastIndexOf("0"), + ["02134", "02134", undefined] ); + +re.lastIndex = s.lastIndexOf("0"); + +AddRegExpCases( re, + "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + + s.lastIndexOf("0"), + s, + s.lastIndexOf("0"), + ["02134", "02134", undefined]); + +re.lastIndex = s.lastIndexOf("0") + 1; + +AddRegExpCases( re, + "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + + s.lastIndexOf("0") +1, + s, + s.lastIndexOf("0"), + ["02134", "02134", undefined]); + +test(); + +function AddRegExpCases( + regexp, str_regexp, string, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(string) == null || matches_array == null ) { + AddTestCase( + string + ".match(" + regexp +")", + matches_array, + string.match(regexp) ); + + return; + } + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + matches_array.length, + string.match(regexp).length ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").index", + index, + string.match(regexp).index ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").input", + string, + string.match(regexp).input ); + + var limit = matches_array.length > string.match(regexp).length ? + matches_array.length : + string.match(regexp).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} + +function AddGlobalRegExpCases( + regexp, str_regexp, string, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(string) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + string +")", + matches_array, + regexp.exec(string) ); + + return; + } + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + matches_array.length, + string.match(regexp).length ); + + var limit = matches_array.length > string.match(regexp).length ? + matches_array.length : + string.match(regexp).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/String/match-003.js b/js/src/tests/ecma_2/String/match-003.js new file mode 100644 index 000000000..24453e621 --- /dev/null +++ b/js/src/tests/ecma_2/String/match-003.js @@ -0,0 +1,132 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/match-003.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * String.match( regexp ) + * + * If regexp is not an object of type RegExp, it is replaced with result + * of the expression new RegExp(regexp). Let string denote the result of + * converting the this value to a string. If regexp.global is false, + * return the result obtained by invoking RegExp.prototype.exec (see + * section 15.7.5.3) on regexp with string as parameter. + * + * Otherwise, set the regexp.lastIndex property to 0 and invoke + * RegExp.prototype.exec repeatedly until there is no match. If there is a + * match with an empty string (in other words, if the value of + * regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1. + * The value returned is an array with the properties 0 through n-1 + * corresponding to the first element of the result of each matching + * invocation of RegExp.prototype.exec. + * + * Note that the match function is intentionally generic; it does not + * require that its this value be a string object. Therefore, it can be + * transferred to other kinds of objects for use as a method. + */ + +var SECTION = "String/match-003.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.match( regexp )"; + +startTest(); + +// the regexp argument is not a RegExp object +// this is not a string object + + +// [if regexp.global is true] set the regexp.lastIndex property to 0 and +// invoke RegExp.prototype.exec repeatedly until there is no match. If +// there is a match with an empty string (in other words, if the value of +// regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1. +// The value returned is an array with the properties 0 through n-1 +// corresponding to the first element of the result of each matching invocation +// of RegExp.prototype.exec. + + +// set the value of lastIndex +re = /([\d]{5})([-\ ]?[\d]{4})?$/g; + + +s = "Boston, MA 02134"; + +AddGlobalRegExpCases( re, + "re = " + re, + s, + ["02134" ]); + +re.lastIndex = 0; + +AddGlobalRegExpCases( + re, + "re = " + re + "; re.lastIndex = 0 ", + s, + ["02134"]); + + +re.lastIndex = s.length; + +AddGlobalRegExpCases( + re, + "re = " + re + "; re.lastIndex = " + s.length, + s, + ["02134"] ); + +re.lastIndex = s.lastIndexOf("0"); + +AddGlobalRegExpCases( + re, + "re = "+ re +"; re.lastIndex = " + s.lastIndexOf("0"), + s, + ["02134"]); + +re.lastIndex = s.lastIndexOf("0") + 1; + +AddGlobalRegExpCases( + re, + "re = " +re+ "; re.lastIndex = " + (s.lastIndexOf("0") +1), + s, + ["02134"]); + +test(); + +function AddGlobalRegExpCases( + regexp, str_regexp, string, matches_array ) { + + // prevent a runtime error + + if ( string.match(regexp) == null || matches_array == null ) { + AddTestCase( + string + ".match(" + str_regexp +")", + matches_array, + string.match(regexp) ); + + return; + } + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + matches_array.length, + string.match(regexp).length ); + + var limit = matches_array.length > string.match(regexp).length ? + matches_array.length : + string.match(regexp).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/String/match-004.js b/js/src/tests/ecma_2/String/match-004.js new file mode 100644 index 000000000..7c17396af --- /dev/null +++ b/js/src/tests/ecma_2/String/match-004.js @@ -0,0 +1,173 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/match-004.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * String.match( regexp ) + * + * If regexp is not an object of type RegExp, it is replaced with result + * of the expression new RegExp(regexp). Let string denote the result of + * converting the this value to a string. If regexp.global is false, + * return the result obtained by invoking RegExp.prototype.exec (see + * section 15.7.5.3) on regexp with string as parameter. + * + * Otherwise, set the regexp.lastIndex property to 0 and invoke + * RegExp.prototype.exec repeatedly until there is no match. If there is a + * match with an empty string (in other words, if the value of + * regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1. + * The value returned is an array with the properties 0 through n-1 + * corresponding to the first element of the result of each matching + * invocation of RegExp.prototype.exec. + * + * Note that the match function is intentionally generic; it does not + * require that its this value be a string object. Therefore, it can be + * transferred to other kinds of objects for use as a method. + * + * + * The match function should be intentionally generic, and not require + * this to be a string. + * + */ + +var SECTION = "String/match-004.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.match( regexp )"; + +var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=345818"; + +startTest(); + +// set the value of lastIndex +re = /0./; +s = 10203040506070809000; + +Number.prototype.match = String.prototype.match; + +AddRegExpCases( re, + "re = " + re , + s, + String(s), + 1, + ["02"]); + + +re.lastIndex = 0; +AddRegExpCases( re, + "re = " + re +" [lastIndex is " + re.lastIndex+"]", + s, + String(s), + 1, + ["02"]); +/* + +re.lastIndex = s.length; + +AddRegExpCases( re, +"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + +s.length, +s, +s.lastIndexOf("0"), +null ); + +re.lastIndex = s.lastIndexOf("0"); + +AddRegExpCases( re, +"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + +s.lastIndexOf("0"), +s, +s.lastIndexOf("0"), +["02134"]); + +re.lastIndex = s.lastIndexOf("0") + 1; + +AddRegExpCases( re, +"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " + +s.lastIndexOf("0") +1, +s, +0, +null); +*/ +test(); + +function AddRegExpCases( + regexp, str_regexp, string, str_string, index, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(string) == null || matches_array == null ) { + AddTestCase( + string + ".match(" + regexp +")", + matches_array, + string.match(regexp) ); + + return; + } + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + matches_array.length, + string.match(regexp).length ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").index", + index, + string.match(regexp).index ); + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").input", + str_string, + string.match(regexp).input ); + + var limit = matches_array.length > string.match(regexp).length ? + matches_array.length : + string.match(regexp).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} + +function AddGlobalRegExpCases( + regexp, str_regexp, string, matches_array ) { + + // prevent a runtime error + + if ( regexp.exec(string) == null || matches_array == null ) { + AddTestCase( + regexp + ".exec(" + string +")", + matches_array, + regexp.exec(string) ); + + return; + } + + AddTestCase( + "( " + string + " ).match(" + str_regexp +").length", + matches_array.length, + string.match(regexp).length ); + + var limit = matches_array.length > string.match(regexp).length ? + matches_array.length : + string.match(regexp).length; + + for ( var matches = 0; matches < limit; matches++ ) { + AddTestCase( + "( " + string + " ).match(" + str_regexp +")[" + matches +"]", + matches_array[matches], + string.match(regexp)[matches] ); + } +} diff --git a/js/src/tests/ecma_2/String/shell.js b/js/src/tests/ecma_2/String/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/String/shell.js diff --git a/js/src/tests/ecma_2/String/split-001.js b/js/src/tests/ecma_2/String/split-001.js new file mode 100644 index 000000000..f8e2c762a --- /dev/null +++ b/js/src/tests/ecma_2/String/split-001.js @@ -0,0 +1,112 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/split-001.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * Since regular expressions have been part of JavaScript since 1.2, there + * are already tests for regular expressions in the js1_2/regexp folder. + * + * These new tests try to supplement the existing tests, and verify that + * our implementation of RegExp conforms to the ECMA specification, but + * does not try to be as exhaustive as in previous tests. + * + * The [,limit] argument to String.split is new, and not covered in any + * existing tests. + * + * String.split cases are covered in ecma/String/15.5.4.8-*.js. + * String.split where separator is a RegExp are in + * js1_2/regexp/string_split.js + * + */ + +var SECTION = "ecma_2/String/split-001.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.split( regexp, [,limit] )"; + +startTest(); + +// the separator is not supplied +// separator is undefined +// separator is an empty string + +AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] ); +AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] ); + +// separartor is a regexp +// separator regexp value global setting is set +// string is an empty string +// if separator is an empty string, split each by character + +// this is not a String object + +// limit is not a number +// limit is undefined +// limit is larger than 2^32-1 +// limit is a negative number + +test(); + +function AddSplitCases( string, separator, str_sep, split_array ) { + + // verify that the result of split is an object of type Array + AddTestCase( + "( " + string + " ).split(" + str_sep +").constructor == Array", + true, + string.split(separator).constructor == Array ); + + // check the number of items in the array + AddTestCase( + "( " + string + " ).split(" + str_sep +").length", + split_array.length, + string.split(separator).length ); + + // check the value of each array item + var limit = (split_array.length > string.split(separator).length ) + ? split_array.length : string.split(separator).length; + + for ( var matches = 0; matches < split_array.length; matches++ ) { + AddTestCase( + "( " + string + " ).split(" + str_sep +")[" + matches +"]", + split_array[matches], + string.split( separator )[matches] ); + } +} + +function AddLimitedSplitCases( + string, separator, str_sep, limit, str_limit, split_array ) { + + // verify that the result of split is an object of type Array + + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + str_limit + + " ).constructor == Array", + true, + string.split(separator, limit).constructor == Array ); + + // check the length of the array + + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + str_limit + " ).length", + length, + string.split(separator).length ); + + // check the value of each array item + + for ( var matches = 0; matches < split_array.length; matches++ ) { + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]", + split_array[matches], + string.split( separator )[matches] ); + } +} diff --git a/js/src/tests/ecma_2/String/split-002.js b/js/src/tests/ecma_2/String/split-002.js new file mode 100644 index 000000000..8f14e4fac --- /dev/null +++ b/js/src/tests/ecma_2/String/split-002.js @@ -0,0 +1,270 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/split-002.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * Since regular expressions have been part of JavaScript since 1.2, there + * are already tests for regular expressions in the js1_2/regexp folder. + * + * These new tests try to supplement the existing tests, and verify that + * our implementation of RegExp conforms to the ECMA specification, but + * does not try to be as exhaustive as in previous tests. + * + * The [,limit] argument to String.split is new, and not covered in any + * existing tests. + * + * String.split cases are covered in ecma/String/15.5.4.8-*.js. + * String.split where separator is a RegExp are in + * js1_2/regexp/string_split.js + * + */ + +var SECTION = "ecma_2/String/split-002.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.split( regexp, [,limit] )"; + +startTest(); + +// the separator is not supplied +// separator is undefined +// separator is an empty string + +// AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] ); +// AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] ); + +// separator is an empty regexp +// separator is not supplied + +CompareSplit( "hello", "ll" ); + +CompareSplit( "hello", "l" ); +CompareSplit( "hello", "x" ); +CompareSplit( "hello", "h" ); +CompareSplit( "hello", "o" ); +CompareSplit( "hello", "hello" ); +CompareSplit( "hello", undefined ); + +CompareSplit( "hello", ""); +CompareSplit( "hello", "hellothere" ); + +CompareSplit( new String("hello" ) ); + + +Number.prototype.split = String.prototype.split; + +CompareSplit( new Number(100111122133144155), 1 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, 1 ); + +CompareSplitWithLimit(new Number(100111122133144155), 1, 2 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, 0 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, 100 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, void 0 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, Math.pow(2,32)-1 ); +CompareSplitWithLimit(new Number(100111122133144155), 1, "boo" ); +CompareSplitWithLimit(new Number(100111122133144155), 1, -(Math.pow(2,32)-1) ); +CompareSplitWithLimit( "hello", "l", NaN ); +CompareSplitWithLimit( "hello", "l", 0 ); +CompareSplitWithLimit( "hello", "l", 1 ); +CompareSplitWithLimit( "hello", "l", 2 ); +CompareSplitWithLimit( "hello", "l", 3 ); +CompareSplitWithLimit( "hello", "l", 4 ); + + +/* + CompareSplitWithLimit( "hello", "ll", 0 ); + CompareSplitWithLimit( "hello", "ll", 1 ); + CompareSplitWithLimit( "hello", "ll", 2 ); + CompareSplit( "", " " ); + CompareSplit( "" ); +*/ + +// separartor is a regexp +// separator regexp value global setting is set +// string is an empty string +// if separator is an empty string, split each by character + +// this is not a String object + +// limit is not a number +// limit is undefined +// limit is larger than 2^32-1 +// limit is a negative number + +test(); + +function CompareSplit( string, separator ) { + split_1 = string.split( separator ); + split_2 = string_split( string, separator ); + + AddTestCase( + "( " + string +".split(" + separator + ") ).length" , + split_2.length, + split_1.length ); + + var limit = split_1.length > split_2.length ? + split_1.length : split_2.length; + + for ( var split_item = 0; split_item < limit; split_item++ ) { + AddTestCase( + string + ".split(" + separator + ")["+split_item+"]", + split_2[split_item], + split_1[split_item] ); + } +} + +function CompareSplitWithLimit( string, separator, splitlimit ) { + split_1 = string.split( separator, splitlimit ); + split_2 = string_split( string, separator, splitlimit ); + + AddTestCase( + "( " + string +".split(" + separator + ", " + splitlimit+") ).length" , + split_2.length, + split_1.length ); + + var limit = split_1.length > split_2.length ? + split_1.length : split_2.length; + + for ( var split_item = 0; split_item < limit; split_item++ ) { + AddTestCase( + string + ".split(" + separator + ", " + splitlimit+")["+split_item+"]", + split_2[split_item], + split_1[split_item] ); + } +} + +function string_split ( __this, separator, limit ) { + var S = String(__this ); // 1 + + var A = new Array(); // 2 + + if ( limit == undefined ) { // 3 + lim = Math.pow(2, 31 ) -1; + } else { + lim = ToUint32( limit ); + } + + var s = S.length; // 4 + var p = 0; // 5 + + if ( separator == undefined ) { // 8 + A[0] = S; + return A; + } + + if ( separator.constructor == RegExp ) // 6 + R = separator; + else + R = separator.toString(); + + if (lim == 0) return A; // 7 + + if ( separator == undefined ) { // 8 + A[0] = S; + return A; + } + + if (s == 0) { // 9 + z = SplitMatch(R, S, 0); + if (z != false) return A; + A[0] = S; + return A; + } + + var q = p; // 10 +loop: + while (true ) { + + if ( q == s ) break; // 11 + + z = SplitMatch(R, S, q); // 12 + +//print("Returned ", z); + + if (z != false) { // 13 + e = z.endIndex; // 14 + cap = z.captures; // 14 + if (e != p) { // 15 +//print("S = ", S, ", p = ", p, ", q = ", q); + T = S.slice(p, q); // 16 +//print("T = ", T); + A[A.length] = T; // 17 + if (A.length == lim) return A; // 18 + p = e; // 19 + i = 0; // 20 + while (true) { // 25 + if (i == cap.length) { // 21 + q = p; // 10 + continue loop; + } + i = i + 1; // 22 + A[A.length] = cap[i] // 23 + if (A.length == lim) return A; // 24 + } + } + } + + q = q + 1; // 26 + } + + T = S.slice(p, q); + A[A.length] = T; + return A; +} + +function SplitMatch(R, S, q) +{ + if (R.constructor == RegExp) { // 1 + var reResult = R.match(S, q); // 8 + if (reResult == undefined) + return false; + else { + a = new Array(reResult.length - 1); + for (var i = 1; i < reResult.length; i++) + a[a.length] = reResult[i]; + return { endIndex : reResult.index + reResult[0].length, captures : cap }; + } + } + else { + var r = R.length; // 2 + s = S.length; // 3 + if ((q + r) > s) return false; // 4 + for (var i = 0; i < r; i++) { +//print("S.charAt(", q + i, ") = ", S.charAt(q + i), ", R.charAt(", i, ") = ", R.charAt(i)); + if (S.charAt(q + i) != R.charAt(i)) // 5 + return false; + } + cap = new Array(); // 6 + return { endIndex : q + r, captures : cap }; // 7 + } +} + +function ToUint32( n ) { + n = Number( n ); + var sign = ( n < 0 ) ? -1 : 1; + + if ( Math.abs( n ) == 0 + || Math.abs( n ) == Number.POSITIVE_INFINITY + || n != n) { + return 0; + } + n = sign * Math.floor( Math.abs(n) ) + + n = n % Math.pow(2,32); + + if ( n < 0 ){ + n += Math.pow(2,32); + } + + return ( n ); +} diff --git a/js/src/tests/ecma_2/String/split-003.js b/js/src/tests/ecma_2/String/split-003.js new file mode 100644 index 000000000..e887dbe0e --- /dev/null +++ b/js/src/tests/ecma_2/String/split-003.js @@ -0,0 +1,123 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: String/split-003.js + * ECMA Section: 15.6.4.9 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ + +/* + * Since regular expressions have been part of JavaScript since 1.2, there + * are already tests for regular expressions in the js1_2/regexp folder. + * + * These new tests try to supplement the existing tests, and verify that + * our implementation of RegExp conforms to the ECMA specification, but + * does not try to be as exhaustive as in previous tests. + * + * The [,limit] argument to String.split is new, and not covered in any + * existing tests. + * + * String.split cases are covered in ecma/String/15.5.4.8-*.js. + * String.split where separator is a RegExp are in + * js1_2/regexp/string_split.js + * + */ + +var SECTION = "ecma_2/String/split-003.js"; +var VERSION = "ECMA_2"; +var TITLE = "String.prototype.split( regexp, [,limit] )"; + +startTest(); + +// separator is a regexp +// separator regexp value global setting is set +// string is an empty string +// if separator is an empty string, split each by character + + +AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] ); + +AddSplitCases( "hello", /l/, "/l/", ["he","","o"] ); +AddLimitedSplitCases( "hello", /l/, "/l/", 0, [] ); +AddLimitedSplitCases( "hello", /l/, "/l/", 1, ["he"] ); +AddLimitedSplitCases( "hello", /l/, "/l/", 2, ["he",""] ); +AddLimitedSplitCases( "hello", /l/, "/l/", 3, ["he","","o"] ); +AddLimitedSplitCases( "hello", /l/, "/l/", 4, ["he","","o"] ); +AddLimitedSplitCases( "hello", /l/, "/l/", void 0, ["he","","o"] ); +AddLimitedSplitCases( "hello", /l/, "/l/", "hi", [] ); +AddLimitedSplitCases( "hello", /l/, "/l/", undefined, ["he","","o"] ); + +AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 0, [] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 1, ["h"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 2, ["h","e"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 3, ["h","e","l"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 4, ["h","e","l","l"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", void 0, ["h","e","l","l","o"] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", "hi", [] ); +AddLimitedSplitCases( "hello", new RegExp, "new RegExp", undefined, ["h","e","l","l","o"] ); + +test(); + +function AddSplitCases( string, separator, str_sep, split_array ) { + // verify that the result of split is an object of type Array + AddTestCase( + "( " + string + " ).split(" + str_sep +").constructor == Array", + true, + string.split(separator).constructor == Array ); + + // check the number of items in the array + AddTestCase( + "( " + string + " ).split(" + str_sep +").length", + split_array.length, + string.split(separator).length ); + + // check the value of each array item + var limit = (split_array.length > string.split(separator).length ) + ? split_array.length : string.split(separator).length; + + for ( var matches = 0; matches < split_array.length; matches++ ) { + AddTestCase( + "( " + string + " ).split(" + str_sep +")[" + matches +"]", + split_array[matches], + string.split( separator )[matches] ); + } +} + +function AddLimitedSplitCases( + string, separator, str_sep, limit, split_array ) { + + // verify that the result of split is an object of type Array + + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + limit + + " ).constructor == Array", + true, + string.split(separator, limit).constructor == Array ); + + // check the length of the array + + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + limit + " ).length", + split_array.length, + string.split(separator, limit).length ); + + // check the value of each array item + + var slimit = (split_array.length > string.split(separator).length ) + ? split_array.length : string.split(separator, limit).length; + + for ( var matches = 0; matches < slimit; matches++ ) { + AddTestCase( + "( " + string + " ).split(" + str_sep +", " + limit + " )[" + matches +"]", + split_array[matches], + string.split( separator, limit )[matches] ); + } +} diff --git a/js/src/tests/ecma_2/browser.js b/js/src/tests/ecma_2/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/browser.js diff --git a/js/src/tests/ecma_2/extensions/browser.js b/js/src/tests/ecma_2/extensions/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/extensions/browser.js diff --git a/js/src/tests/ecma_2/extensions/constructor-001.js b/js/src/tests/ecma_2/extensions/constructor-001.js new file mode 100644 index 000000000..5c5466008 --- /dev/null +++ b/js/src/tests/ecma_2/extensions/constructor-001.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/constructor-001.js + * ECMA Section: 15.7.3.3 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/constructor-001"; +var VERSION = "ECMA_2"; +var TITLE = "new RegExp()"; + +startTest(); + +/* + * for each test case, verify: + * - verify that [[Class]] property is RegExp + * - prototype property should be set to RegExp.prototype + * - source is set to the empty string + * - global property is set to false + * - ignoreCase property is set to false + * - multiline property is set to false + * - lastIndex property is set to 0 + */ + +RegExp.prototype.getClassProperty = Object.prototype.toString; +var re = new RegExp(); + +AddTestCase( + "new RegExp().__proto__", + RegExp.prototype, + re.__proto__ + ); + +test() diff --git a/js/src/tests/ecma_2/extensions/function-001.js b/js/src/tests/ecma_2/extensions/function-001.js new file mode 100644 index 000000000..df45e048d --- /dev/null +++ b/js/src/tests/ecma_2/extensions/function-001.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: RegExp/function-001.js + * ECMA Section: 15.7.2.1 + * Description: Based on ECMA 2 Draft 7 February 1999 + * + * Author: christine@netscape.com + * Date: 19 February 1999 + */ +var SECTION = "RegExp/function-001"; +var VERSION = "ECMA_2"; +var TITLE = "RegExp( pattern, flags )"; + +startTest(); + +/* + * for each test case, verify: + * - verify that [[Class]] property is RegExp + * - prototype property should be set to RegExp.prototype + * - source is set to the empty string + * - global property is set to false + * - ignoreCase property is set to false + * - multiline property is set to false + * - lastIndex property is set to 0 + */ + +RegExp.prototype.getClassProperty = Object.prototype.toString; +var re = new RegExp(); + +AddTestCase( + "new RegExp().__proto__", + RegExp.prototype, + re.__proto__ + ); + +test() diff --git a/js/src/tests/ecma_2/extensions/instanceof-001.js b/js/src/tests/ecma_2/extensions/instanceof-001.js new file mode 100644 index 000000000..69aab1bfa --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-001.js @@ -0,0 +1,111 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: instanceof-001.js + * ECMA Section: 11.8.6 + * Description: + * + * RelationalExpression instanceof Identifier + * + * Author: christine@netscape.com + * Date: 2 September 1998 + */ +var SECTION = "instanceof-001"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof" + + startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object_1, object_2, expect ) { + result = object_1 instanceof object_2; + + new TestCase( + SECTION, + "(" + object_1 + ") instanceof " + object_2, + expect, + result ); +} + +function Gen3(value) { + this.value = value; + this.generation = 3; + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); +} +Gen3.name = 3; +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); + +function Gen2(value) { + this.value = value; + this.generation = 2; +} +Gen2.name = 2; +Gen2.prototype = new Gen3(); + +function Gen1(value) { + this.value = value; + this.generation = 1; +} +Gen1.name = 1; +Gen1.prototype = new Gen2(); + +function Gen0(value) { + this.value = value; + this.generation = 0; +} +Gen0.name = 0; +Gen0.prototype = new Gen1(); + + +function GenA(value) { + this.value = value; + this.generation = "A"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); + +} +GenA.prototype = new Gen0(); +GenA.name = "A"; + +function GenB(value) { + this.value = value; + this.generation = "B"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); +} +GenB.name = "B" + GenB.prototype = void 0; + +// RelationalExpression is not an object. + +InstanceOf( true, Boolean, false ); +InstanceOf( new Boolean(false), Boolean, true ); + +// __proto__ of RelationalExpression is null. should return false +genA = new GenA(); +genA.__proto__ = null; + +InstanceOf( genA, GenA, false ); + +// RelationalExpression.__proto__ == (but not ===) Identifier.prototype + +InstanceOf( new Gen2(), Gen0, false ); +InstanceOf( new Gen2(), Gen1, false ); +InstanceOf( new Gen2(), Gen2, true ); +InstanceOf( new Gen2(), Gen3, true ); + +// RelationalExpression.__proto__.__proto__ === Identifier.prototype +InstanceOf( new Gen0(), Gen0, true ); +InstanceOf( new Gen0(), Gen1, true ); +InstanceOf( new Gen0(), Gen2, true ); +InstanceOf( new Gen0(), Gen3, true ); + +InstanceOf( new Gen0(), Object, true ); +InstanceOf( new Gen0(), Function, false ); + +InstanceOf( Gen0, Function, true ); +InstanceOf( Gen0, Object, true ); + +test(); diff --git a/js/src/tests/ecma_2/extensions/instanceof-002.js b/js/src/tests/ecma_2/extensions/instanceof-002.js new file mode 100644 index 000000000..65708f12a --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-002.js @@ -0,0 +1,127 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: instanceof-002.js + Section: + Description: Determining Instance Relationships + + This test is the same as js1_3/inherit/proto-002, except that it uses + the builtin instanceof operator rather than a user-defined function + called InstanceOf. + + This tests Object Hierarchy and Inheritance, as described in the document + Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97 + 15:19:34 on http://devedge.netscape.com/. Current URL: + http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm + + This tests the syntax ObjectName.prototype = new PrototypeObject using the + Employee example in the document referenced above. + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +// onerror = err; + +var SECTION = "instanceof-002"; +var VERSION = "ECMA_2"; +var TITLE = "Determining Instance Relationships"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object, constructor ) { + while ( object != null ) { + if ( object == constructor.prototype ) { + return true; + } + object = object.__proto__; + } + return false; +} + +function Employee ( name, dept ) { + this.name = name || ""; + this.dept = dept || "general"; +} + +function Manager () { + this.reports = []; +} +Manager.prototype = new Employee(); + +function WorkerBee ( name, dept, projs ) { + this.base = Employee; + this.base( name, dept) + this.projects = projs || new Array(); +} +WorkerBee.prototype = new Employee(); + +function SalesPerson () { + this.dept = "sales"; + this.quota = 100; +} +SalesPerson.prototype = new WorkerBee(); + +function Engineer ( name, projs, machine ) { + this.base = WorkerBee; + this.base( name, "engineering", projs ) + this.machine = machine || ""; +} +Engineer.prototype = new WorkerBee(); + +var pat = new Engineer(); + +new TestCase( SECTION, + "pat.__proto__ == Engineer.prototype", + true, + pat.__proto__ == Engineer.prototype ); + +new TestCase( SECTION, + "pat.__proto__.__proto__ == WorkerBee.prototype", + true, + pat.__proto__.__proto__ == WorkerBee.prototype ); + +new TestCase( SECTION, + "pat.__proto__.__proto__.__proto__ == Employee.prototype", + true, + pat.__proto__.__proto__.__proto__ == Employee.prototype ); + +new TestCase( SECTION, + "pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype", + true, + pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype ); + +new TestCase( SECTION, + "pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null", + true, + pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null ); + +new TestCase( SECTION, + "pat instanceof Engineer", + true, + pat instanceof Engineer ); + +new TestCase( SECTION, + "pat instanceof WorkerBee )", + true, + pat instanceof WorkerBee ); + +new TestCase( SECTION, + "pat instanceof Employee )", + true, + pat instanceof Employee ); + +new TestCase( SECTION, + "pat instanceof Object )", + true, + pat instanceof Object ); + +new TestCase( SECTION, + "pat instanceof SalesPerson )", + false, + pat instanceof SalesPerson ); +test(); diff --git a/js/src/tests/ecma_2/extensions/instanceof-003-n.js b/js/src/tests/ecma_2/extensions/instanceof-003-n.js new file mode 100644 index 000000000..1b3937ac8 --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-003-n.js @@ -0,0 +1,88 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: instanceof-001.js + * ECMA Section: 11.8.6 + * Description: + * + * RelationalExpression instanceof Identifier + * + * Author: christine@netscape.com + * Date: 2 September 1998 + */ +var SECTION = "instanceof-003-n"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof" + + startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object_1, object_2, expect ) { + + result = object_1 instanceof object_2; + + new TestCase( + SECTION, + "(" + object_1 + ") instanceof " + object_2, + expect, + result ); +} + +function Gen3(value) { + this.value = value; + this.generation = 3; + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); +} +Gen3.name = 3; +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); + +function Gen2(value) { + this.value = value; + this.generation = 2; +} +Gen2.name = 2; +Gen2.prototype = new Gen3(); + +function Gen1(value) { + this.value = value; + this.generation = 1; +} +Gen1.name = 1; +Gen1.prototype = new Gen2(); + +function Gen0(value) { + this.value = value; + this.generation = 0; +} +Gen0.name = 0; +Gen0.prototype = new Gen1(); + + +function GenA(value) { + this.value = value; + this.generation = "A"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); + +} +GenA.prototype = new Gen0(); +GenA.name = "A"; + +function GenB(value) { + this.value = value; + this.generation = "B"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); +} +GenB.name = "B" + GenB.prototype = void 0; + +// Identifier is not a function +DESCRIPTION = "Identifier is not a function"; +EXPECTED = "error"; + +InstanceOf( true, true, "error" ); + +test(); diff --git a/js/src/tests/ecma_2/extensions/instanceof-004-n.js b/js/src/tests/ecma_2/extensions/instanceof-004-n.js new file mode 100644 index 000000000..18de1c8da --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-004-n.js @@ -0,0 +1,88 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: instanceof-001.js + * ECMA Section: 11.8.6 + * Description: + * + * RelationalExpression instanceof Identifier + * + * Author: christine@netscape.com + * Date: 2 September 1998 + */ +var SECTION = "instanceof-004-n"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof" + + startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object_1, object_2, expect ) { + result = object_1 instanceof object_2; + + new TestCase( + SECTION, + "(" + object_1 + ") instanceof " + object_2, + expect, + result ); +} + +function Gen3(value) { + this.value = value; + this.generation = 3; + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); +} +Gen3.name = 3; +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); + +function Gen2(value) { + this.value = value; + this.generation = 2; +} +Gen2.name = 2; +Gen2.prototype = new Gen3(); + +function Gen1(value) { + this.value = value; + this.generation = 1; +} +Gen1.name = 1; +Gen1.prototype = new Gen2(); + +function Gen0(value) { + this.value = value; + this.generation = 0; +} +Gen0.name = 0; +Gen0.prototype = new Gen1(); + + +function GenA(value) { + this.value = value; + this.generation = "A"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); + +} +GenA.prototype = new Gen0(); +GenA.name = "A"; + +function GenB(value) { + this.value = value; + this.generation = "B"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); +} +GenB.name = "B" + GenB.prototype = void 0; + +// Identifier is not a function + +DESCRIPTION = "Identifier is not a function"; +EXPECTED = "error"; + +InstanceOf( new Boolean(true), false, "error" ); + +test(); diff --git a/js/src/tests/ecma_2/extensions/instanceof-005-n.js b/js/src/tests/ecma_2/extensions/instanceof-005-n.js new file mode 100644 index 000000000..8f02162ca --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-005-n.js @@ -0,0 +1,89 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: instanceof-001.js + * ECMA Section: 11.8.6 + * Description: + * + * RelationalExpression instanceof Identifier + * + * Author: christine@netscape.com + * Date: 2 September 1998 + */ +var SECTION = "instanceof-005-n"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof" + + startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object_1, object_2, expect ) { + result = object_1 instanceof object_2; + + new TestCase( + SECTION, + "(" + object_1 + ") instanceof " + object_2, + expect, + result ); +} + +function Gen3(value) { + this.value = value; + this.generation = 3; + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); +} +Gen3.name = 3; +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); + +function Gen2(value) { + this.value = value; + this.generation = 2; +} +Gen2.name = 2; +Gen2.prototype = new Gen3(); + +function Gen1(value) { + this.value = value; + this.generation = 1; +} +Gen1.name = 1; +Gen1.prototype = new Gen2(); + +function Gen0(value) { + this.value = value; + this.generation = 0; +} +Gen0.name = 0; +Gen0.prototype = new Gen1(); + + +function GenA(value) { + this.value = value; + this.generation = "A"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); + +} +GenA.prototype = new Gen0(); +GenA.name = "A"; + +function GenB(value) { + this.value = value; + this.generation = "B"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); +} +GenB.name = "B" + GenB.prototype = void 0; + + +// Identifier is a function, prototype of Identifier is not an object + +DESCRIPTION = "Identifier is a function, prototype of Identifier is not an object"; +EXPECTED = "error"; + +InstanceOf( new GenB(), GenB, "error" ); + +test(); diff --git a/js/src/tests/ecma_2/extensions/instanceof-006.js b/js/src/tests/ecma_2/extensions/instanceof-006.js new file mode 100644 index 000000000..9f18c4e10 --- /dev/null +++ b/js/src/tests/ecma_2/extensions/instanceof-006.js @@ -0,0 +1,86 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: instanceof-001.js + * ECMA Section: 11.8.6 + * Description: + * + * RelationalExpression instanceof Identifier + * + * Author: christine@netscape.com + * Date: 2 September 1998 + */ +var SECTION = "instanceof-001"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof" + + startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +function InstanceOf( object_1, object_2, expect ) { + result = object_1 instanceof object_2; + + new TestCase( + SECTION, + "(" + object_1 + ") instanceof " + object_2, + expect, + result ); +} + +function Gen3(value) { + this.value = value; + this.generation = 3; + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); +} +Gen3.name = 3; +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); + +function Gen2(value) { + this.value = value; + this.generation = 2; +} +Gen2.name = 2; +Gen2.prototype = new Gen3(); + +function Gen1(value) { + this.value = value; + this.generation = 1; +} +Gen1.name = 1; +Gen1.prototype = new Gen2(); + +function Gen0(value) { + this.value = value; + this.generation = 0; +} +Gen0.name = 0; +Gen0.prototype = new Gen1(); + + +function GenA(value) { + this.value = value; + this.generation = "A"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); + +} +GenA.prototype = new Gen0(); +GenA.name = "A"; + +function GenB(value) { + this.value = value; + this.generation = "B"; + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); +} +GenB.name = "B" + GenB.prototype = void 0; + +// RelationalExpression is not an object. + +// InstanceOf( true, Boolean, false ); +InstanceOf( new Boolean(false), Boolean, true ); + +test(); diff --git a/js/src/tests/ecma_2/extensions/shell.js b/js/src/tests/ecma_2/extensions/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/extensions/shell.js diff --git a/js/src/tests/ecma_2/instanceof/browser.js b/js/src/tests/ecma_2/instanceof/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/browser.js diff --git a/js/src/tests/ecma_2/instanceof/instanceof-001.js b/js/src/tests/ecma_2/instanceof/instanceof-001.js new file mode 100644 index 000000000..9bdc7bfe3 --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/instanceof-001.js @@ -0,0 +1,34 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: instanceof-1.js + ECMA Section: + Description: instanceof operator + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = ""; +var VERSION = "ECMA_2"; +var TITLE = "instanceof operator"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var b = new Boolean(); + +new TestCase( SECTION, + "var b = new Boolean(); b instanceof Boolean", + true, + b instanceof Boolean ); + +new TestCase( SECTION, + "b instanceof Object", + true, + b instanceof Object ); + +test(); diff --git a/js/src/tests/ecma_2/instanceof/instanceof-002.js b/js/src/tests/ecma_2/instanceof/instanceof-002.js new file mode 100644 index 000000000..6b2bb7f4f --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/instanceof-002.js @@ -0,0 +1,51 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: + ECMA Section: + Description: Call Objects + + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ +var SECTION = ""; +var VERSION = "ECMA_2"; +var TITLE = "The Call Constructor"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var b = new Boolean(); + +new TestCase( SECTION, + "var b = new Boolean(); b instanceof Boolean", + true, + b instanceof Boolean ); + +new TestCase( SECTION, + "b instanceof Object", + true, + b instanceof Object ); + +new TestCase( SECTION, + "b instanceof Array", + false, + b instanceof Array ); + +new TestCase( SECTION, + "true instanceof Boolean", + false, + true instanceof Boolean ); + +new TestCase( SECTION, + "Boolean instanceof Object", + true, + Boolean instanceof Object ); +test(); + diff --git a/js/src/tests/ecma_2/instanceof/instanceof-003.js b/js/src/tests/ecma_2/instanceof/instanceof-003.js new file mode 100644 index 000000000..1021914e9 --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/instanceof-003.js @@ -0,0 +1,65 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: instanceof-003.js + ECMA Section: + Description: http://bugzilla.mozilla.org/show_bug.cgi?id=7635 + + js> function Foo() {} + js> theproto = {}; + [object Object] + js> Foo.prototype = theproto + [object Object] + js> theproto instanceof Foo + true + + I think this should be 'false' + + + Author: christine@netscape.com + Date: 12 november 1997 + + Modified to conform to ECMA3 + https://bugzilla.mozilla.org/show_bug.cgi?id=281606 +*/ +var SECTION = "instanceof-003"; +var VERSION = "ECMA_2"; +var TITLE = "instanceof operator"; +var BUGNUMBER ="7635"; + +startTest(); + +function Foo() {}; +theproto = {}; +Foo.prototype = theproto; + +AddTestCase( + "function Foo() = {}; theproto = {}; Foo.prototype = theproto; " + + "theproto instanceof Foo", + false, + theproto instanceof Foo ); + + +var o = {}; + +// https://bugzilla.mozilla.org/show_bug.cgi?id=281606 +try +{ + AddTestCase( + "o = {}; o instanceof o", + "error", + o instanceof o ); +} +catch(e) +{ + AddTestCase( + "o = {}; o instanceof o", + "error", + "error" ); +} + +test(); diff --git a/js/src/tests/ecma_2/instanceof/regress-7635.js b/js/src/tests/ecma_2/instanceof/regress-7635.js new file mode 100644 index 000000000..7ea94e037 --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/regress-7635.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: regress-7635.js + * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=7635 + * Description: instanceof tweaks + * Author: + */ + +var SECTION = "instanceof"; // provide a document reference (ie, ECMA section) +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for Bugzilla #7635"; // Provide ECMA section title or a description +var BUGNUMBER = "7635"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +function Foo() {} +theproto = {}; +Foo.prototype = theproto + theproto instanceof Foo + + + AddTestCase( "function Foo() {}; theproto = {}; Foo.prototype = theproto; theproto instanceof Foo", + false, + theproto instanceof Foo ); + +var f = new Function(); + +AddTestCase( "var f = new Function(); f instanceof f", false, f instanceof f ); + + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/ecma_2/instanceof/shell.js b/js/src/tests/ecma_2/instanceof/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_2/instanceof/shell.js diff --git a/js/src/tests/ecma_2/shell.js b/js/src/tests/ecma_2/shell.js new file mode 100644 index 000000000..f744c6d29 --- /dev/null +++ b/js/src/tests/ecma_2/shell.js @@ -0,0 +1,18 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var TZ_DIFF = getTimeZoneDiff(); + +/* + * Originally, the test suite used a hard-coded value TZ_DIFF = -8. + * But that was only valid for testers in the Pacific Standard Time Zone! + * We calculate the proper number dynamically for any tester. We just + * have to be careful to use a date not subject to Daylight Savings Time... + */ +function getTimeZoneDiff() +{ + return -((new Date(2000, 1, 1)).getTimezoneOffset())/60; +} diff --git a/js/src/tests/ecma_2/template.js b/js/src/tests/ecma_2/template.js new file mode 100644 index 000000000..6217968cd --- /dev/null +++ b/js/src/tests/ecma_2/template.js @@ -0,0 +1,26 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: + */ + + +/** + * File Name: template.js + * Reference: ** replace with bugzilla URL or document reference ** + * Description: ** replace with description of test ** + * Author: ** replace with your e-mail address ** + */ + +var SECTION = ""; // if ECMA test, provide section number +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = ""; // Provide ECMA section title or description +var BUGNUMBER = ""; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + + +/* Calls to AddTestCase here */ + +test(); // leave this alone |