JavaScript Tests - regression tests for bug 346642, by Jesse Ruderman, Brendan Eich

This commit is contained in:
bclary%bclary.com 2006-09-30 13:04:48 +00:00
Родитель b02bee621f
Коммит 05b22ec2b7
6 изменённых файлов: 596 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,198 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
* Brendan Eich
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var bug = 346642;
var summary = 'decompilation of destructuring assignment';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
var f;
f = function () {({a:{c:x}, b:x}) = ({b:3})}
expect = 'function () {({a:{c:x}, b:x} = {b:3});}';
actual = f + '';
compareSource(expect, actual, summary + ': 1');
f = function() { for(; let (x=3,y=4) null;) { } }
expect = 'function() { for(; let (x=3,y=4) null;) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 2');
f = function() { let (x=3,y=4) { } x = 5; }
expect = 'function() { let (x=3,y=4) { } x = 5; }';
actual = f + '';
compareSource(expect, actual, summary + ': 3');
f = function () { for ([11].x;;) break; }
expect = 'function () { for ([11].x;;) { break;} }';
actual = f + '';
compareSource(expect, actual, summary + ': 4');
f = function() { new ({ a: b } = c) }
expect = 'function() { new ({ a: b } = c); }';
actual = f + '';
compareSource(expect, actual, summary + ': 5');
f = function () { (let (x) 3)(); }
expect = 'function () { (let (x) 3)(); }';
actual = f + '';
compareSource(expect, actual, summary + ': 6');
f = function () { (let (x) 3).foo(); }
expect = 'function () { (let (x) 3).foo(); }';
actual = f + '';
compareSource(expect, actual, summary + ': 7');
f = function () { ({x: a(b)}) = window; }
expect = 'function () { ({x: a(b)} = window); }';
actual = f + '';
compareSource(expect, actual, summary + ': 8');
f = function() { let ([a]=x) { } }
expect = 'function() { let ([a]=x) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 9');
f = function( ){ new ([x] = k) }
expect = 'function( ){ new ([x] = k); }';
actual = f + '';
compareSource(expect, actual, summary + ': 10');
f = function() { [a] = [b] = c }
expect = 'function() { [a] = [b] = c; }';
actual = f + '';
compareSource(expect, actual, summary + ': 11');
f = function() { [] = 3 }
expect = 'function() { [] = 3; }';
actual = f + '';
compareSource(expect, actual, summary + ': 12');
f = function() { ({}) = 3 }
expect = 'function() { ({}) = 3; }';
actual = f + '';
compareSource(expect, actual, summary + ': 13');
f = function () { while( {} = e ) ; }
expect = 'function () { while( {} = e ) ; }';
actual = f + '';
compareSource(expect, actual, summary + ': 14');
f = function () { while( {} = (a)(b) ) ; }
expect = 'function () { while( {} = (a)(b) ) {} }';
actual = f + '';
compareSource(expect, actual, summary + ': 15');
f = function (){[] = [a,b,c]}
expect = 'function (){[] = [a,b,c];}';
actual = f + '';
compareSource(expect, actual, summary + ': 16');
f = function (){for([] = [a,b,c];;);}
expect = 'function (){for([] = [a,b,c];;){}}';
actual = f + '';
compareSource(expect, actual, summary + ': 17');
f = function (){for(;;[] = [a,b,c]);}
expect = 'function (){for(;;[] = [a,b,c]){}}';
actual = f + '';
compareSource(expect, actual, summary + ': 18');
f = function (){for(let [] = [a,b,c];;);}
expect = 'function (){for(let [] = [a,b,c];;){}}';
actual = f + '';
compareSource(expect, actual, summary + ': 19');
f = function() { for (;; [x] = [1]) { } }
expect = 'function() { for (;; [x] = [1]) { } } ';
actual = f + '';
compareSource(expect, actual, summary + ': 20');
f = function() { [g['//']] = h }
expect = 'function() { [g["//"]] = h; }';
actual = f + '';
compareSource(expect, actual, summary + ': 21');
f = (function() { for ( let [a,b]=[c,d] in [3]) { } })
expect = 'function() { for ( let [a,b]=[c,d] in [3]) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 22');
f = function () { while(1) [a] = [b]; }
expect = 'function () { while(1) {[a] = [b];} } ';
actual = f + '';
compareSource(expect, actual, summary + ': 23');
f = function () { for(var [x, y] = r in p) { } }
expect = 'function () { for(var [x, y] = r in p) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 24');
f = function() { for([x] = [];;) { } }
expect = 'function() { for([x] = [];;) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 25');
f = function () { let ([y] = delete [1]) { } }
expect = 'function () { let ([y] = ([1], true)) { } }';
actual = f + '';
compareSource(expect, actual, summary + ': 26');
f = function () { delete 4..x }
expect = 'function () { delete 4..x; }';
actual = f + '';
compareSource(expect, actual, summary + ': 27');
f = function() { return [({ x: y }) = p for (z in 5)] }
expect = 'function() { return [{ x: y } = p for (z in 5)]; }';
actual = f + '';
compareSource(expect, actual, summary + ': 1');
exitFunc ('test');
}

Просмотреть файл

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
* Brendan Eich
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var bug = 346642;
var summary = 'decompilation of destructuring assignment';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
var f;
f = function f() { [z] = 3 }
expect = 'function f() { [z] = 3; }';
actual = f + '';
compareSource(expect, actual, summary);
expect = actual = 'No Crash';
writeLineToLog(uneval(f));
reportCompare(expect, actual, 'writeLineToLog(uneval(f))');
exitFunc ('test');
}

Просмотреть файл

@ -0,0 +1,167 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
* Brendan Eich
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var bug = 346642;
var summary = 'decompilation of destructuring assignment';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
expect = 'TypeError: NaN is not a constructor';
actual = 'No Crash';
try
{
try { throw 1; } catch(e1 if 0) { } catch(e2 if (new NaN)) { }
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 1');
expect = 'TypeError: x.t has no properties';
actual = 'No Crash';
try
{
z = [1];
let (x = (undefined ? 3 : z)) { x.t.g }
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 2');
expect = 'TypeError: x.t has no properties';
actual = 'No Crash';
try
{
z = [1];
new Function("let (x = (undefined ? 3 : z)) { x.t.g }")()
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 3');
expect = 'TypeError: b is not a constructor';
actual = 'No Crash';
try
{
with({x: (new (b = 1))}) (2).x
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 4');
expect = 'TypeError: this.zzz has no properties';
actual = 'No Crash';
try
{
(function(){try { } catch(f) { return; } finally { this.zzz.zzz }})();
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 5');
expect = 'TypeError: p.z = <x><y/></x> ? 3 : 4 is not a function';
actual = 'No Crash';
try
{
(new Function("if(\n({y:5, p: (print).r})) { p={}; (p.z = <x\n><y/></x> ? 3 : 4)(5) }"))();
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 6');
expect = 'TypeError: xx is not a function';
actual = 'No Crash';
try
{
switch(xx) { case 3: case (new ([3].map)): } const xx;
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 7');
expect = 'TypeError: ++x is not a function';
actual = 'No Crash';
try
{
let (x=3) ((++x)())
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 8');
expect = 'ReferenceError: x.y is not defined';
actual = 'No Crash';
try
{
x = {};
import x.y;
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary + ': 9');
exitFunc ('test');
}

Просмотреть файл

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
* Brendan Eich
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under let (x=3) ((++x)())
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var bug = 346642;
var summary = 'decompilation of destructuring assignment';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
expect = 'No Crash';
actual = 'No Crash';
try
{
function() { for (var [a, b] in []) for ([c, d] in []) { } }
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
* Brendan Eich
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under let (x=3) ((++x)())
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var bug = 346642;
var summary = 'decompilation of destructuring assignment';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
expect = 3;
actual = '';
"" + function() { [] = 3 }; actual = 3;
actual = 3;
reportCompare(expect, actual, summary + ': 1');
var z = 6;
var f = function (){for(let [] = []; false;) let z; return z}
expect = f();
actual = eval(""+f)()
reportCompare(expect, actual, summary + ': 2');
expect = 3;
actual = '';
"" + function () { for(;; [[a]] = [5]) { } }; actual = 3;
reportCompare(expect, actual, summary + ': 3');
expect = 3;
actual = '';
f = function () { return { set x([a]) { yield; } } }
var obj = f();
uneval(obj); actual = 3;
reportCompare(expect, actual, summary + ': 4');
expect = 3;
actual = '';
"" + function () { [y([a]=b)] = z }; actual = 3;
reportCompare(expect, actual, summary + ': 5');
expect = 3;
actual = '';
"" + function () { for(;; ([[,]] = p)) { } }; actual = 3;
reportCompare(expect, actual, summary + ': 6');
expect = 3;
actual = '';
actual = 1; for(x in (function ([y]) { })() ) { } actual = 3;
reportCompare(expect, actual, summary + ': 7');
exitFunc ('test');
}