diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
| commit | 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (patch) | |
| tree | 11425ea0b299d6fb89c6d3618a22d97d5bf68d0f /JavaScriptCore/tests/mozilla/js1_2/function | |
| parent | 648161bb0edfc3d43db63caed5cc5213bc6cb78f (diff) | |
| download | external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.zip external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.gz external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.bz2 | |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'JavaScriptCore/tests/mozilla/js1_2/function')
12 files changed, 1158 insertions, 0 deletions
diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/Function_object.js b/JavaScriptCore/tests/mozilla/js1_2/function/Function_object.js new file mode 100644 index 0000000..1dec16a --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/Function_object.js @@ -0,0 +1,85 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + Filename: Function_object.js + Description: 'Testing Function objects' + + Author: Nick Lerissa + Date: April 17, 1998 +*/ + + var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; + var VERSION = 'no version'; + startTest(); + var TITLE = 'functions: Function_object'; + + writeHeaderToLog('Executing script: Function_object.js'); + writeHeaderToLog( SECTION + " "+ TITLE); + + var count = 0; + var testcases = new Array(); + + + function a_test_function(a,b,c) + { + return a + b + c; + } + + f = a_test_function; + + + testcases[count++] = new TestCase( SECTION, "f.name", + 'a_test_function', f.name); + + testcases[count++] = new TestCase( SECTION, "f.length", + 3, f.length); + + testcases[count++] = new TestCase( SECTION, "f.arity", + 3, f.arity); + + testcases[count++] = new TestCase( SECTION, "f(2,3,4)", + 9, f(2,3,4)); + + var fnName = version() == 120 ? '' : 'anonymous'; + + testcases[count++] = new TestCase( SECTION, "(new Function()).name", + fnName, (new Function()).name); + + testcases[count++] = new TestCase( SECTION, "(new Function()).toString()", + '\nfunction ' + fnName + '() {\n}\n', (new Function()).toString()); + + function test() + { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); + } + + test(); + diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/Number.js b/JavaScriptCore/tests/mozilla/js1_2/function/Number.js new file mode 100644 index 0000000..9586f78 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/Number.js @@ -0,0 +1,98 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + Filename: Number.js + Description: 'This tests the function Number(Object)' + + Author: Nick Lerissa + Date: Fri Feb 13 09:58:28 PST 1998 +*/ + + var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; + var VERSION = 'no version'; + startTest(); + var TITLE = 'functions: Number'; + var BUGNUMBER="123435"; + + writeHeaderToLog('Executing script: Number.js'); + writeHeaderToLog( SECTION + " "+ TITLE); + + var count = 0; + var testcases = new Array(); + + + date = new Date(2200); + + testcases[count++] = new TestCase( SECTION, "Number(new Date(2200)) ", + 2200, (Number(date))); + testcases[count++] = new TestCase( SECTION, "Number(true) ", + 1, (Number(true))); + testcases[count++] = new TestCase( SECTION, "Number(false) ", + 0, (Number(false))); + testcases[count++] = new TestCase( SECTION, "Number('124') ", + 124, (Number('124'))); + testcases[count++] = new TestCase( SECTION, "Number('1.23') ", + 1.23, (Number('1.23'))); + testcases[count++] = new TestCase( SECTION, "Number({p:1}) ", + NaN, (Number({p:1}))); + testcases[count++] = new TestCase( SECTION, "Number(null) ", + 0, (Number(null))); + testcases[count++] = new TestCase( SECTION, "Number(-45) ", + -45, (Number(-45))); + + // http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123435 + // under js1.2, Number([1,2,3]) should return 3. + + /* + http://bugs.webkit.org/show_bug.cgi?id=11545#c4 + According to ECMA 9.3, when input type was Object, should call + ToPrimitive(input arg, hint Number) first, and than ToNumber() later. However, + ToPrimitive() will use [[DefaultValue]](hint) rule when input Type was Object + (ECMA 8.6.2.6). So the input [1,2,3] will applied [[DefaultValue]](hint) rule + with hint Number, and it looks like this: + + toString(valuOf([1,2,3])) => toString(1,2,3) => '1,2,3' + + Than ToNumber('1,2,3') results NaN based on ECMA 9.3.1: If the grammar cannot + interpret the string as an expansion of StringNumericLiteral, then the result + of ToNumber is NaN. + */ + + //testcases[count++] = new TestCase( SECTION, "Number([1,2,3]) ", + // 3, (Number([1,2,3]))); + + function test() + { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); + } + + test(); + diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/String.js b/JavaScriptCore/tests/mozilla/js1_2/function/String.js new file mode 100644 index 0000000..724c392 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/String.js @@ -0,0 +1,99 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + Filename: String.js + Description: 'This tests the function String(Object)' + + Author: Nick Lerissa + Date: Fri Feb 13 09:58:28 PST 1998 +*/ + + var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; + var VERSION = 'no version'; + startTest(); + var TITLE = 'functions: String'; + + writeHeaderToLog('Executing script: String.js'); + writeHeaderToLog( SECTION + " "+ TITLE); + + var count = 0; + var testcases = new Array(); + + + testcases[count++] = new TestCase( SECTION, "String(true) ", + 'true', (String(true))); + testcases[count++] = new TestCase( SECTION, "String(false) ", + 'false', (String(false))); + testcases[count++] = new TestCase( SECTION, "String(-124) ", + '-124', (String(-124))); + testcases[count++] = new TestCase( SECTION, "String(1.23) ", + '1.23', (String(1.23))); + /* + http://bugs.webkit.org/show_bug.cgi?id=11545#c5 + According to ECMA 9.8, when input type of String object argument was Object, we + should applied ToPrimitive(input arg, hint String) first, and later ToString(). + And just like previous one, ToPrimitive() will use [[DefaultValue]](hint) + with hint String to convert the input (toString() below uses the rule in ECMA 15.2.4.2): + + valueOf(toString({p:1}) => valueOf('[object Object]') => '[object Object]' + + And ToString() called after ToPrimitive(), so the correct result would be: + + [object Object] + */ + //testcases[count++] = new TestCase( SECTION, "String({p:1}) ", + // '{p:1}', (String({p:1}))); + testcases[count++] = new TestCase( SECTION, "String(null) ", + 'null', (String(null))); + /* + http://bugs.webkit.org/show_bug.cgi?id=11545#c5 + According to ECMA 9.8, when input type of String object argument was Object, we + should applied ToPrimitive(input arg, hint String) first, and later ToString(). + And just like previous one, ToPrimitive() will use [[DefaultValue]](hint) + with hint String to convert the input (toString() below uses the rule in ECMA 15.2.4.2): + + valueOf(toString([1,2,3])) => valueOf('1,2,3') => '1,2,3' + + And ToString() called after ToPrimitive(), so the correct result would be: + + 1,2,3 + */ + //testcases[count++] = new TestCase( SECTION, "String([1,2,3]) ", + // '[1, 2, 3]', (String([1,2,3]))); + + + function test() + { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); + } + + test(); + diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/definition-1.js b/JavaScriptCore/tests/mozilla/js1_2/function/definition-1.js new file mode 100644 index 0000000..6daea71 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/definition-1.js @@ -0,0 +1,73 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: definition-1.js + Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=111284 + Description: Regression test for declaring functions. + + Author: christine@netscape.com + Date: 15 June 1998 +*/ + + var SECTION = "function/definition-1.js"; + var VERSION = "JS_12"; + startTest(); + var TITLE = "Regression test for 111284"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + f1 = function() { return "passed!" } + + function f2() { f3 = function() { return "passed!" }; return f3(); } + + testcases[tc++] = new TestCase( SECTION, + 'f1 = function() { return "passed!" }; f1()', + "passed!", + f1() ); + + testcases[tc++] = new TestCase( SECTION, + 'function f2() { f3 = function { return "passed!" }; return f3() }; f2()', + "passed!", + f2() ); + + testcases[tc++] = new TestCase( SECTION, + 'f3()', + "passed!", + f3() ); + + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/function-001-n.js b/JavaScriptCore/tests/mozilla/js1_2/function/function-001-n.js new file mode 100644 index 0000000..5ae01a9 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/function-001-n.js @@ -0,0 +1,74 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + * 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 = "JS1_1"; + startTest(); + var TITLE = "functions not separated by semicolons are errors in version 120 and higher"; + var BUGNUMBER="99232"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + testcases[tc++] = new TestCase( + SECTION, + "eval(\"function f(){}function g(){}\")", + "error", + eval("function f(){}function g(){}") ); + + test(); + + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/length.js b/JavaScriptCore/tests/mozilla/js1_2/function/length.js new file mode 100644 index 0000000..aae30d5 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/length.js @@ -0,0 +1,93 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.3.5.1.js + ECMA Section: Function.length + Description: + + The value of the length property is usually an integer that indicates the + "typical" number of arguments expected by the function. However, the + language permits the function to be invoked with some other number of + arguments. The behavior of a function when invoked on a number of arguments + other than the number specified by its length property depends on the function. + + This checks the pre-ecma behavior Function.length. + + http://scopus.mcom.com/bugsplat/show_bug.cgi?id=104204 + + + Author: christine@netscape.com + Date: 12 november 1997 +*/ + + var SECTION = "function/length.js"; + var VERSION = "ECMA_1"; + startTest(); + var TITLE = "Function.length"; + var BUGNUMBER="104204"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + var f = new Function( "a","b", "c", "return f.length"); + + if ( version() <= 120 ) { + + testcases[tc++] = new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f()', + 0, + f() ); + + testcases[tc++] = new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)', + 5, + f(1,2,3,4,5) ); + } else { + + testcases[tc++] = new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f()', + 3, + f() ); + + testcases[tc++] = new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)', + 3, + f(1,2,3,4,5) ); + + + } + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/nesting-1.js b/JavaScriptCore/tests/mozilla/js1_2/function/nesting-1.js new file mode 100644 index 0000000..391f926 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/nesting-1.js @@ -0,0 +1,61 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: nesting-1.js + Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=122040 + Description: Regression test for a nested function + + Author: christine@netscape.com + Date: 15 June 1998 +*/ + + var SECTION = "function/nesting-1.js"; + var VERSION = "JS_12"; + startTest(); + var TITLE = "Regression test for 122040"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + function f(a) {function g(b) {return a+b;}; return g;}; f(7) + + testcases[tc++] = new TestCase( SECTION, + 'function f(a) {function g(b) {return a+b;}; return g;}; typeof f(7)', + "function", + typeof f(7) ); + + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/nesting.js b/JavaScriptCore/tests/mozilla/js1_2/function/nesting.js new file mode 100644 index 0000000..b626da5 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/nesting.js @@ -0,0 +1,83 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + Filename: nesting.js + Description: 'This tests the nesting of functions' + + Author: Nick Lerissa + Date: Fri Feb 13 09:58:28 PST 1998 +*/ + + var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; + var VERSION = 'no version'; + startTest(); + var TITLE = 'functions: nesting'; + + writeHeaderToLog('Executing script: nesting.js'); + writeHeaderToLog( SECTION + " "+ TITLE); + + var count = 0; + var testcases = new Array(); + + + function outer_func(x) + { + var y = "outer"; + + testcases[count++] = new TestCase( SECTION, "outer:x ", + 1111, x); + testcases[count++] = new TestCase( SECTION, "outer:y ", + 'outer', y); + function inner_func(x) + { + var y = "inner"; + testcases[count++] = new TestCase( SECTION, "inner:x ", + 2222, x); + testcases[count++] = new TestCase( SECTION, "inner:y ", + 'inner', y); + }; + + inner_func(2222); + testcases[count++] = new TestCase( SECTION, "outer:x ", + 1111, x); + testcases[count++] = new TestCase( SECTION, "outer:y ", + 'outer', y); + } + + outer_func(1111); + + function test() + { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); + } + + test(); + diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-1.js b/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-1.js new file mode 100644 index 0000000..b01825c --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-1.js @@ -0,0 +1,98 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: regexparg-1.js + Description: + + Regression test for + http://scopus/bugsplat/show_bug.cgi?id=122787 + Passing a regular expression as the first constructor argument fails + + Author: christine@netscape.com + Date: 15 June 1998 +*/ + + var SECTION = "JS_1.2"; + var VERSION = "JS_1.2"; + startTest(); + var TITLE = "The variable statment"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + function f(x) {return x;} + + x = f(/abc/); + + testcases[tc++] = new TestCase( SECTION, + "function f(x) {return x;}; f()", + void 0, + f() ); + + testcases[tc++] = new TestCase( SECTION, + "f(\"hi\")", + "hi", + f("hi") ); + + testcases[tc++] = new TestCase( SECTION, + "new f(/abc/) +''", + "/abc/", + new f(/abc/) +"" ); + + testcases[tc++] = new TestCase( SECTION, + "f(/abc/)+'')", + "/abc/", + f(/abc/) +''); + + testcases[tc++] = new TestCase( SECTION, + "typeof f(/abc/)", + "function", + typeof f(/abc/) ); + + testcases[tc++] = new TestCase( SECTION, + "typeof new f(/abc/)", + "function", + typeof new f(/abc/) ); + + testcases[tc++] = new TestCase( SECTION, + "x = new f(/abc/); x(\"hi\")", + null, + x("hi") ); + + + // js> x() + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-2-n.js b/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-2-n.js new file mode 100644 index 0000000..e8bf951 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/regexparg-2-n.js @@ -0,0 +1,66 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: regexparg-1.js + Description: + + Regression test for + http://scopus/bugsplat/show_bug.cgi?id=122787 + Passing a regular expression as the first constructor argument fails + + Author: christine@netscape.com + Date: 15 June 1998 +*/ + + var SECTION = "JS_1.2"; + var VERSION = "JS_1.2"; + startTest(); + var TITLE = "The variable statment"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + function f(x) {return x;} + + x = f(/abc/); + + testcases[tc++] = new TestCase( SECTION, + "function f(x) {return x;}; x = f(/abc/); x()", + "error", + x() ); + + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/tostring-1.js b/JavaScriptCore/tests/mozilla/js1_2/function/tostring-1.js new file mode 100644 index 0000000..d532d65 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/tostring-1.js @@ -0,0 +1,143 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: tostring-1.js + Section: Function.toString + Description: + + Since the behavior of Function.toString() is implementation-dependent, + toString tests for function are not in the ECMA suite. + + Currently, an attempt to parse the toString output for some functions + and verify that the result is something reasonable. + + Author: christine@netscape.com + Date: 12 november 1997 +*/ + + var SECTION = "tostring-1"; + var VERSION = "JS1_2"; + startTest(); + var TITLE = "Function.toString()"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + var tab = " "; + + t1 = new TestFunction( "stub", "value", tab + "return value;" ); + + t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" ); + + t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" + + tab + "return s;" ); + + t4 = new TestFunction( "noop", "value" ); + + t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" ); + + var f = new Function( "return \"hello!\""); + + testcases[tc++] = new TestCase( SECTION, + "stub.toString()", + t1.valueOf(), + stub.toString() ); + + testcases[tc++] = new TestCase( SECTION, + "ToString.toString()", + t2.valueOf(), + ToString.toString() ); + + testcases[tc++] = new TestCase( SECTION, + "Add.toString()", + t3.valueOf(), + Add.toString() ); + + testcases[tc++] = new TestCase( SECTION, + "noop.toString()", + t4.toString(), + noop.toString() ); + + testcases[tc++] = new TestCase( SECTION, + "f.toString()", + t5.toString(), + f.toString() ); + test(); + +function noop( value ) { +} +function Add( a, b, c, d, e ) { + var s = a + b + c + d + e; + return s; +} +function stub( value ) { + return value; +} +function ToString( object ) { + return object + ""; +} + +function ToBoolean( value ) { + if ( value == 0 || value == NaN || value == false ) { + return false; + } else { + return true; + } +} + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} + +function TestFunction( name, args, body ) { + if ( name == "anonymous" && version() == 120 ) { + name = ""; + } + + this.name = name; + this.arguments = args.toString(); + this.body = body; + + /* the format of Function.toString() in JavaScript 1.2 is: + /n + function name ( arguments ) { + body + } + */ + this.value = "\nfunction " + (name ? name : "" )+ + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}\n"; + + this.toString = new Function( "return this.value" ); + this.valueOf = new Function( "return this.value" ); + return this; +} diff --git a/JavaScriptCore/tests/mozilla/js1_2/function/tostring-2.js b/JavaScriptCore/tests/mozilla/js1_2/function/tostring-2.js new file mode 100644 index 0000000..146764d --- /dev/null +++ b/JavaScriptCore/tests/mozilla/js1_2/function/tostring-2.js @@ -0,0 +1,185 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: tostring-1.js + Section: Function.toString + Description: + + Since the behavior of Function.toString() is implementation-dependent, + toString tests for function are not in the ECMA suite. + + Currently, an attempt to parse the toString output for some functions + and verify that the result is something reasonable. + + This verifies + http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212 + + Author: christine@netscape.com + Date: 12 november 1997 +*/ + + var SECTION = "tostring-2"; + var VERSION = "JS1_2"; + startTest(); + var TITLE = "Function.toString()"; + var BUGNUMBER="123444"; + + writeHeaderToLog( SECTION + " "+ TITLE); + + var testcases = new Array(); + + var tab = " "; + + +var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" ); +function Equals (a, b) { + return a == b; +} + +var reallyequals = new TestFunction( "ReallyEquals", "a, b", + ( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" ); +function ReallyEquals( a, b ) { + return a === b; +} + +var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" ); +function DoesntEqual( a, b ) { + return a != b; +} + +var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b", + ( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" ); +function ReallyDoesntEqual( a, b ) { + return a !== b; +} + +var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+ + tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" ); +function TestOr( a ) { + if ( a == null || a == void 0 ) + return 0; + else + return a; +} + +var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+ + tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" ); +function TestAnd( a ) { + if ( a != null && a != void 0 ) + return a; + else + return 0; +} + +var or = new TestFunction( "Or", "a, b", tab + "return a | b;" ); +function Or( a, b ) { + return a | b; +} + +var and = new TestFunction( "And", "a, b", tab + "return a & b;" ); +function And( a, b ) { + return a & b; +} + +var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" ); +function XOr( a, b ) { + return a ^ b; +} + + testcases[testcases.length] = new TestCase( SECTION, + "Equals.toString()", + equals.valueOf(), + Equals.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "ReallyEquals.toString()", + reallyequals.valueOf(), + ReallyEquals.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "DoesntEqual.toString()", + doesntequal.valueOf(), + DoesntEqual.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "ReallyDoesntEqual.toString()", + reallydoesntequal.valueOf(), + ReallyDoesntEqual.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "TestOr.toString()", + testor.valueOf(), + TestOr.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "TestAnd.toString()", + testand.valueOf(), + TestAnd.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "Or.toString()", + or.valueOf(), + Or.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "And.toString()", + and.valueOf(), + And.toString() ); + + testcases[testcases.length] = new TestCase( SECTION, + "XOr.toString()", + xor.valueOf(), + XOr.toString() ); + + test(); + +function test() { + for ( tc=0; tc < testcases.length; tc++ ) { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return ( testcases ); +} +function TestFunction( name, args, body ) { + this.name = name; + this.arguments = args.toString(); + this.body = body; + + /* the format of Function.toString() in JavaScript 1.2 is: + /n + function name ( arguments ) { + body + } + */ + this.value = "\nfunction " + (name ? name : "anonymous" )+ + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}\n"; + + this.toString = new Function( "return this.value" ); + this.valueOf = new Function( "return this.value" ); + return this; +} |
