Adding new files from sputniktests r97

This commit is contained in:
Mark Miller 2011-06-27 08:58:09 -06:00
parent a230618291
commit a7e6453c0e
26 changed files with 408 additions and 0 deletions

View File

@ -0,0 +1,18 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.10.6.2_A12;
* @section: 15.10.6.2;
* @assertion: regExp exec() acts like regExp.exec('undefined') (step 2);
* @description: Checking RegExp.prototype.exec.length;
*/
(/foo/).test('xfoox');
var match = new RegExp('(.|\r|\n)*','').exec()[0];
if (match === 'xfoox') {
$FAIL('#1: regExp.exec() leaks match globally');
}
if (match !== 'undefined') {
$FAIL('#2: regExp.exec() must coerce absent first arg to "undefined"');
}

View File

@ -0,0 +1,19 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.12.2_A1;
* @section: 15.12.2;
* @assertion: JSON.parse must create a property with the given
* property name;
* @description: Tests that JSON.parse treats "__proto__" as a regular
* property name;
*/
var x = JSON.parse('{"__proto__":[]}');
if (Object.getPrototypeOf(x) !== Object.prototype) {
$FAIL('#1: JSON.parse confused by "__proto__"');
}
if (!Array.isArray(x.__proto__)) {
$FAIL('#2: JSON.parse did not set "__proto__" as a regular property');
}

View File

@ -0,0 +1,12 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.2.4.4_A14;
* @section: 15.2.4.4;
* @assertion: Let O be the result of calling ToObject passing the this
* value as the argument.
* @negative
*/
(1,Object.prototype.valueOf)();

View File

@ -0,0 +1,13 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.2_A12;
* @section: 15.3.4.2;
* @assertion: The Function.prototype.toString function is not generic;
* it throws a TypeError exception if its this value is not
* a Function object.
* @negative TypeError;
*/
Function.prototype.toString.call(undefined);

View File

@ -0,0 +1,13 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.2_A13;
* @section: 15.3.4.2;
* @assertion: The toString function is not generic; it throws a
* TypeError exception if its this value is not a Function
* object.
* @negative TypeError;
*/
Function.prototype.toString.call(null);

View File

@ -0,0 +1,13 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.2_A14;
* @section: 15.3.4.2;
* @assertion: The toString function is not generic; it throws a
* TypeError exception if its this value is not a Function
* object.
* @negative TypeError;
*/
Function.prototype.toString.call({});

View File

@ -0,0 +1,16 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.2_A15;
* @section: 15.3.4.2;
* @assertion: The toString function is not generic; it throws a
* TypeError exception if its this value is not a Function
* object.
* @description: Whether or not they are callable, RegExp objects are
* not Function objects, so toString should throw a
* TypeError.
* @negative TypeError;
*/
Function.prototype.toString.call(/x/);

View File

@ -0,0 +1,18 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.2_A16;
* @section: 15.3.4.2;
* @assertion: The toString function is not generic; it throws a
* TypeError exception if its this value is not a Function
* object.
* @description: The String constructor, given an object, should invoke
* that object's toString method as a method, i.e., with
* its this value bound to that object.
* @negative TypeError;
*/
var obj = {toString: Function.prototype.toString};
String(obj);

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.3_A13;
* @section: 15.3.4.3;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.apply.call(undefined, {}, []);

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.3_A14;
* @section: 15.3.4.3;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.apply.call(null, {}, []);

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.3_A15;
* @section: 15.3.4.3;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.apply.call({}, {}, []);

View File

@ -0,0 +1,27 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.3_A16;
* @section: 15.3.4.3;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @description: A RegExp is not a function, but it may be
* callable. Iff it is, it's typeof should be 'function',
* in which case apply should accept it as a valid this
* value.
*/
var re = (/x/);
if (typeof re === 'function') {
Function.prototype.apply.call(re, undefined, ['x']);
} else {
try {
Function.prototype.bind.call(re, undefined);
$FAIL('#1: If IsCallable(func) is false, ' +
'then (bind should) throw a TypeError exception');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1: TypeError expected. Actual: ' + e);
}
}
}

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.4_A13;
* @section: 15.3.4.4;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.call.call(undefined, {});

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.4_A14;
* @section: 15.3.4.4;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.call.call(null, {});

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.4_A15;
* @section: 15.3.4.4;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.call.call({}, {});

View File

@ -0,0 +1,27 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.4_A16;
* @section: 15.3.4.4;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @description: A RegExp is not a function, but it may be
* callable. Iff it is, it's typeof should be 'function',
* in which case call should accept it as a valid this
* value.
*/
var re = (/x/);
if (typeof re === 'function') {
Function.prototype.call.call(re, undefined, 'x');
} else {
try {
Function.prototype.bind.call(re, undefined);
$FAIL('#1: If IsCallable(func) is false, ' +
'then (bind should) throw a TypeError exception');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1: TypeError expected. Actual: ' + e);
}
}
}

View File

@ -0,0 +1,15 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A1;
* @section: 15.3.4.5;
* @assertion: "caller" of bound function is poisoned (step 20);
* @description A bound function should fail to find its "caller";
* @negative TypeError;
*/
function foo() { return bar.caller; }
var bar = foo.bind({});
function baz() { return bar(); }
baz();

View File

@ -0,0 +1,12 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A13;
* @section: 15.3.4.5;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.bind.call(undefined, {});

View File

@ -0,0 +1,12 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A14;
* @section: 15.3.4.5;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.bind.call(null, {});

View File

@ -0,0 +1,12 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A15;
* @section: 15.3.4.5;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @negative TypeError;
*/
Function.prototype.bind.call({}, {});

View File

@ -0,0 +1,27 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A16;
* @section: 15.3.4.5;
* @assertion: If IsCallable(func) is false, then throw a TypeError exception.
* @description: A RegExp is not a function, but it may be
* callable. Iff it is, it's typeof should be 'function',
* in which case bind should accept it as a valid this
* value.
*/
var re = (/x/);
if (typeof re === 'function') {
Function.prototype.bind.call(re, undefined);
} else {
try {
Function.prototype.bind.call(re, undefined);
$FAIL('#1: If IsCallable(func) is false, ' +
'then (bind should) throw a TypeError exception');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1: TypeError expected. Actual: ' + e);
}
}
}

View File

@ -0,0 +1,16 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.3.4.5_A1;
* @section: 15.3.4.5;
* @assertion: "arguments" of bound function is poisoned (step 21);
* @description a bound function should fail to find the bound function
* "arguments";
* @negative TypeError;
*/
function foo() { return bar.arguments; }
var bar = foo.bind({});
function baz() { return bar(); }
baz();

View File

@ -0,0 +1,24 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.4.4.11_A8;
* @section: 15.4.4.11;
* @assertion: Call the comparefn passing undefined as the this value
* (step 13b);
* @description: comparefn tests that its this value is undefined;
*/
var global = this;
[2,3].sort(function(x,y) {
"use strict";
if (this === global) {
$FAIL('#1: Sort leaks global');
}
if (this !== undefined) {
$FAIL('#2: Sort comparefn should be called with this===undefined. ' +
'Actual: ' + this);
}
return x - y;
});

View File

@ -0,0 +1,11 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.4.4.18_A1;
* @section: 15.4.4.18;
* @assertion: array.forEach can be frozen while in progress
* @description: Freezes array.forEach during a forEach to see if it works
*/
['z'].forEach(function(){ Object.freeze(Array.prototype.forEach); });

View File

@ -0,0 +1,14 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.4.4.18_A2;
* @section: 15.4.4.18;
* @assertion: array.forEach can be frozen while in progress
* @description: Freezes array.forEach during a forEach to see if it works
*/
function foo() {
['z'].forEach(function(){ Object.freeze(Array.prototype.forEach); });
}
foo();

View File

@ -0,0 +1,23 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @name: S15.5.4.11_A12;
* @section: 15.5.4.11;
* @assertion: Call replaceValue passing undefined as the this value;
* @description: replaceValue tests that its this value is undefined;
*/
var global = this;
'x'.replace(/x/, function() {
"use strict";
if (this === global) {
$FAIL('#1: String replace leaks global');
}
if (this !== undefined) {
$FAIL('#2: replaceValue should be called with this===undefined. ' +
'Actual: ' + this);
}
return 'y';
});