mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for %FunctionPrototype% restricted properties
This commit is contained in:
parent
afa25f6cdc
commit
f398421ee7
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
ECMAScript Function objects defined using syntactic constructors
|
||||||
|
in strict mode code do not have own properties "caller" or
|
||||||
|
"arguments", but inherit them from %FunctionPrototype%.
|
||||||
|
flags: [onlyStrict]
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function func() {}
|
||||||
|
|
||||||
|
assert.sameValue(func.hasOwnProperty('caller'), false, 'Functions defined using syntactic constructors in strict mode code do not have own property "caller"');
|
||||||
|
assert.sameValue(func.hasOwnProperty('arguments'), false, 'Functions defined using syntactic constructors in strict mode code do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return func.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
func.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return func.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
func.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
var newfunc = new Function('"use strict"');
|
||||||
|
|
||||||
|
assert.sameValue(newfunc.hasOwnProperty('caller'), false, 'strict Functions created using Function constructor do not have own property "caller"');
|
||||||
|
assert.sameValue(newfunc.hasOwnProperty('arguments'), false, 'strict Functions created using Function constructor do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return newfunc.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
newfunc.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return newfunc.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
newfunc.arguments = {};
|
||||||
|
});
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-20-1
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - 'caller' is defined as one property of
|
|
||||||
'F'
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
return obj.hasOwnProperty("caller");
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-20-4
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - The [[Enumerable]] attribute of 'caller'
|
|
||||||
property in 'F' is false
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
var canEnumerable = false;
|
|
||||||
var hasProperty = false;
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
hasProperty = obj.hasOwnProperty("caller");
|
|
||||||
for (var prop in obj) {
|
|
||||||
if (prop === "caller") {
|
|
||||||
canEnumerable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasProperty && !canEnumerable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,26 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-20-5
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - The [[Configurable]] attribute of
|
|
||||||
'caller' property in 'F' is false
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
var canConfigurable = false;
|
|
||||||
var hasProperty = false;
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
hasProperty = obj.hasOwnProperty("caller");
|
|
||||||
delete obj.caller;
|
|
||||||
canConfigurable = obj.hasOwnProperty("caller");
|
|
||||||
return hasProperty && canConfigurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-21-1
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - 'arguments' is defined as one property
|
|
||||||
of 'F'
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
return obj.hasOwnProperty("arguments");
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-21-4
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - The [[Enumerable]] attribute of
|
|
||||||
'arguments' property in 'F' is false
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
var canEnumerable = false;
|
|
||||||
var hasProperty = false;
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
hasProperty = obj.hasOwnProperty("arguments");
|
|
||||||
for (var prop in obj) {
|
|
||||||
if (prop === "arguments") {
|
|
||||||
canEnumerable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasProperty && !canEnumerable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,26 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 15.3.4.5-21-5
|
|
||||||
description: >
|
|
||||||
Function.prototype.bind - The [[Configurable]] attribute of
|
|
||||||
'arguments' property in 'F' is false
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
|
|
||||||
var canConfigurable = false;
|
|
||||||
var hasProperty = false;
|
|
||||||
function foo() { }
|
|
||||||
var obj = foo.bind({});
|
|
||||||
hasProperty = obj.hasOwnProperty("arguments");
|
|
||||||
delete obj.caller;
|
|
||||||
canConfigurable = !obj.hasOwnProperty("arguments");
|
|
||||||
return hasProperty && !canConfigurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
32
test/built-ins/Function/prototype/bind/BoundFunction_restricted-properties.js
vendored
Normal file
32
test/built-ins/Function/prototype/bind/BoundFunction_restricted-properties.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using Function.prototype.bind() do not have own
|
||||||
|
properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function target() {}
|
||||||
|
var bound = target.bind(null);
|
||||||
|
|
||||||
|
assert.sameValue(bound.hasOwnProperty('caller'), false, 'Functions created using Function.prototype.bind() do not have own property "caller"');
|
||||||
|
assert.sameValue(bound.hasOwnProperty('arguments'), false, 'Functions created using Function.prototype.bind() do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return bound.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
bound.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return bound.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
bound.arguments = {};
|
||||||
|
});
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Intrinsic %FunctionPrototype% has poisoned own property "arguments"
|
||||||
|
includes:
|
||||||
|
- propertyHelper.js
|
||||||
|
es6id: 8.2.2 S12, 9.2.7
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var FunctionPrototype = Function.prototype;
|
||||||
|
|
||||||
|
assert.sameValue(FunctionPrototype.hasOwnProperty('arguments'), true, 'The result of %FunctionPrototype%.hasOwnProperty("arguments") is true');
|
||||||
|
var descriptor = Object.getOwnPropertyDescriptor(FunctionPrototype, 'arguments');
|
||||||
|
assert.sameValue(typeof descriptor.get, 'function', '%FunctionPrototype%.arguments is an accessor property');
|
||||||
|
assert.sameValue(typeof descriptor.set, 'function', '%FunctionPrototype%.arguments is an accessor property');
|
||||||
|
assert.sameValue(descriptor.get, descriptor.set, '%FunctionPrototype%.arguments getter/setter are both %ThrowTypeError%');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return FunctionPrototype.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
FunctionPrototype.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyNotEnumerable(FunctionPrototype, 'arguments');
|
||||||
|
verifyConfigurable(FunctionPrototype, 'arguments');
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Intrinsic %FunctionPrototype% has poisoned own property "caller"
|
||||||
|
includes:
|
||||||
|
- propertyHelper.js
|
||||||
|
es6id: 8.2.2 S12, 9.2.7
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var FunctionPrototype = Function.prototype;
|
||||||
|
|
||||||
|
assert.sameValue(FunctionPrototype.hasOwnProperty('caller'), true, 'The result of %FunctionPrototype%.hasOwnProperty("caller") is true');
|
||||||
|
|
||||||
|
var descriptor = Object.getOwnPropertyDescriptor(FunctionPrototype, 'caller');
|
||||||
|
assert.sameValue(typeof descriptor.get, 'function', '%FunctionPrototype%.caller is an accessor property');
|
||||||
|
assert.sameValue(typeof descriptor.set, 'function', '%FunctionPrototype%.caller is an accessor property');
|
||||||
|
assert.sameValue(descriptor.get, descriptor.set, '%FunctionPrototype%.caller getter/setter are both %ThrowTypeError%');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return FunctionPrototype.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
FunctionPrototype.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyNotEnumerable(FunctionPrototype, 'caller');
|
||||||
|
verifyConfigurable(FunctionPrototype, 'caller');
|
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using ArrowFunction syntactic form do not have
|
||||||
|
own properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var arrowFn = () => {};
|
||||||
|
|
||||||
|
assert.sameValue(arrowFn.hasOwnProperty('caller'), false, 'Functions created using ArrowFunction syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(arrowFn.hasOwnProperty('arguments'), false, 'Functions created using ArrowFunction syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return arrowFn.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
arrowFn.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return arrowFn.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
arrowFn.arguments = {};
|
||||||
|
});
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using ClassDeclaration syntactic form do not
|
||||||
|
have own properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class BaseClass {}
|
||||||
|
|
||||||
|
assert.sameValue(BaseClass.hasOwnProperty('caller'), false, 'Functions created using ClassDeclaration syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(BaseClass.hasOwnProperty('arguments'), false, 'Functions created using ClassDeclaration syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return BaseClass.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
BaseClass.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return BaseClass.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
BaseClass.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
class SubClass extends BaseClass {}
|
||||||
|
|
||||||
|
assert.sameValue(SubClass.hasOwnProperty('caller'), false, 'Functions created using ClassDeclaration syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(SubClass.hasOwnProperty('arguments'), false, 'Functions created using ClassDeclaration syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return SubClass.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
SubClass.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return SubClass.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
SubClass.arguments = {};
|
||||||
|
});
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using ClassExpression syntactic form do not
|
||||||
|
have own properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var BaseClass = class {};
|
||||||
|
|
||||||
|
assert.sameValue(BaseClass.hasOwnProperty('caller'), false, 'Functions created using ClassExpression syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(BaseClass.hasOwnProperty('arguments'), false, 'Functions created using ClassExpression syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return BaseClass.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
BaseClass.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return BaseClass.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
BaseClass.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
var SubClass = class extends BaseClass {};
|
||||||
|
|
||||||
|
assert.sameValue(SubClass.hasOwnProperty('caller'), false, 'Functions created using ClassExpression syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(SubClass.hasOwnProperty('arguments'), false, 'Functions created using ClassExpression syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return SubClass.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
SubClass.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return SubClass.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
SubClass.arguments = {};
|
||||||
|
});
|
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using MethodDefinition syntactic form do not
|
||||||
|
have own properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
es6id: 16.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class Class {
|
||||||
|
method() {}
|
||||||
|
get accessor() {}
|
||||||
|
set accessor(x) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var instance = new Class;
|
||||||
|
var accessor = Object.getOwnPropertyDescriptor(Class.prototype, "accessor");
|
||||||
|
|
||||||
|
assert.sameValue(instance.method.hasOwnProperty('caller'), false, 'Functions created using MethodDefinition syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(instance.method.hasOwnProperty('arguments'), false, 'Functions created using MethodDefinition syntactic form do not have own property "arguments"');
|
||||||
|
assert.sameValue(accessor.get.hasOwnProperty('caller'), false, 'Accessor Functions created using MethodDefinition syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(accessor.get.hasOwnProperty('arguments'), false, 'Accessor Functions created using MethodDefinition syntactic form do not have own property "arguments"');
|
||||||
|
assert.sameValue(accessor.set.hasOwnProperty('caller'), false, 'Accessor Functions created using MethodDefinition syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(accessor.set.hasOwnProperty('arguments'), false, 'Accessor Functions created using MethodDefinition syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
// --- Test method restricted properties throw
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return instance.method.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
instance.method.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return instance.method.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
instance.method.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- Test getter restricted properties throw
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return accessor.get.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
accessor.get.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return accessor.get.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
accessor.get.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- Test setter restricted properties throw
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return accessor.set.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
accessor.set.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return accessor.set.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
accessor.set.arguments = {};
|
||||||
|
});
|
||||||
|
|
53
test/language/generators/Generator_restricted-properties.js
Normal file
53
test/language/generators/Generator_restricted-properties.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Functions created using GeneratorFunction syntactic form do not
|
||||||
|
have own properties "caller" or "arguments", but inherit them from
|
||||||
|
%FunctionPrototype%.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function* generator() {}
|
||||||
|
|
||||||
|
assert.sameValue(generator.hasOwnProperty('caller'), false, 'Functions created using ArrowFunction syntactic form do not have own property "caller"');
|
||||||
|
assert.sameValue(generator.hasOwnProperty('arguments'), false, 'Functions created using ArrowFunction syntactic form do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return generator.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
generator.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return generator.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
generator.arguments = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
var Generator = Object.getPrototypeOf(generator);
|
||||||
|
var GeneratorFunction = Generator.constructor;
|
||||||
|
var newgenerator = new GeneratorFunction();
|
||||||
|
|
||||||
|
assert.sameValue(newgenerator.hasOwnProperty('caller'), false, 'Generators created using GeneratorFunction constructor do not have own property "caller"');
|
||||||
|
assert.sameValue(newgenerator.hasOwnProperty('arguments'), false, 'Generators created using GeneratorFunction constructor do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return newgenerator.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
newgenerator.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return newgenerator.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
newgenerator.arguments = {};
|
||||||
|
});
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-29-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'caller' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
function foo() {"use strict";}
|
|
||||||
return ! Object.getOwnPropertyDescriptor(foo,
|
|
||||||
"caller").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,20 +1,32 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
// Copyright (C) 2015 Caitlin Potter. All rights reserved.
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
es5id: 13.2-30-s
|
description: >
|
||||||
description: >
|
Functions created using Function.prototype.bind() do not have own
|
||||||
StrictMode - property named 'caller' of function objects is not
|
properties "caller" or "arguments", but inherit them from
|
||||||
configurable
|
%FunctionPrototype%.
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
function testcase() {
|
function target() {}
|
||||||
return ! Object.getOwnPropertyDescriptor(Function("'use strict';"),
|
var self = {};
|
||||||
"caller").configurable;
|
var bound = target.bind(self);
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
assert.sameValue(bound.hasOwnProperty('caller'), false, 'Functions created using Function.prototype.bind() do not have own property "caller"');
|
||||||
|
assert.sameValue(bound.hasOwnProperty('arguments'), false, 'Functions created using Function.prototype.bind() do not have own property "arguments"');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return bound.caller;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
bound.caller = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
return bound.arguments;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
bound.arguments = {};
|
||||||
|
});
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-31-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'caller' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
return ! Object.getOwnPropertyDescriptor(new Function("'use strict';"),
|
|
||||||
"caller").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-32-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'caller' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
var funcExpr = function () { "use strict";};
|
|
||||||
return ! Object.getOwnPropertyDescriptor(funcExpr,
|
|
||||||
"caller").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-33-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'arguments' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
function foo() {"use strict";}
|
|
||||||
return ! Object.getOwnPropertyDescriptor(foo,
|
|
||||||
"arguments").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-34-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'arguments' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
return ! Object.getOwnPropertyDescriptor(Function("'use strict';"),
|
|
||||||
"arguments").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-35-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'arguments' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
return ! Object.getOwnPropertyDescriptor(new Function("'use strict';"),
|
|
||||||
"arguments").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
|
||||||
// Ecma International makes this code available under the terms and conditions set
|
|
||||||
// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
|
|
||||||
// "Use Terms"). Any redistribution of this code must retain the above
|
|
||||||
// copyright and this notice and otherwise comply with the Use Terms.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2-36-s
|
|
||||||
description: >
|
|
||||||
StrictMode - property named 'arguments' of function objects is not
|
|
||||||
configurable
|
|
||||||
flags: [onlyStrict]
|
|
||||||
includes: [runTestCase.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
function testcase() {
|
|
||||||
var funcExpr = function () { "use strict";};
|
|
||||||
return ! Object.getOwnPropertyDescriptor(funcExpr,
|
|
||||||
"arguments").configurable;
|
|
||||||
}
|
|
||||||
runTestCase(testcase);
|
|
@ -1,49 +0,0 @@
|
|||||||
// Copyright 2011 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 13.2.3_A1
|
|
||||||
description: >
|
|
||||||
check that all poisoning use the [[ThrowTypeError]] function
|
|
||||||
object.
|
|
||||||
flags: [onlyStrict]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
var poison = Object.getOwnPropertyDescriptor(function() {}, 'caller').get;
|
|
||||||
|
|
||||||
if (typeof poison !== 'function') {
|
|
||||||
$ERROR("#1: A strict function's .caller should be poisoned with a function");
|
|
||||||
}
|
|
||||||
var threw = null;
|
|
||||||
try {
|
|
||||||
poison();
|
|
||||||
} catch (err) {
|
|
||||||
threw = err;
|
|
||||||
}
|
|
||||||
if (!threw || !(threw instanceof TypeError)) {
|
|
||||||
$ERROR("#2: Poisoned property should throw TypeError");
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkPoison(obj, name) {
|
|
||||||
var desc = Object.getOwnPropertyDescriptor(obj, name);
|
|
||||||
if (desc.enumerable) {
|
|
||||||
$ERROR("#3: Poisoned " + name + " should not be enumerable");
|
|
||||||
}
|
|
||||||
if (desc.configurable) {
|
|
||||||
$ERROR("#4: Poisoned " + name + " should not be configurable");
|
|
||||||
}
|
|
||||||
if (poison !== desc.get) {
|
|
||||||
$ERROR("#5: " + name + "'s getter not poisoned with same poison");
|
|
||||||
}
|
|
||||||
if (poison !== desc.set) {
|
|
||||||
$ERROR("#6: " + name + "'s setter not poisoned with same poison");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkPoison(function() {}, 'caller');
|
|
||||||
checkPoison(function() {}, 'arguments');
|
|
||||||
checkPoison((function() { return arguments; })(), 'caller');
|
|
||||||
checkPoison((function() { return arguments; })(), 'callee');
|
|
||||||
checkPoison((function() {}).bind(null), 'caller');
|
|
||||||
checkPoison((function() {}).bind(null), 'arguments');
|
|
Loading…
x
Reference in New Issue
Block a user