Merge pull request #391 from bocoup/Reflect

Add tests for Reflect
This commit is contained in:
Gorkem Yakin 2015-09-04 12:22:35 -07:00
commit fb09f50296
144 changed files with 3856 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1
description: >
The Reflect object is an ordinary object.
info: >
26.1 The Reflect Object
The Reflect object is the %Reflect% intrinsic object and the initial value of
the Reflect property of the global object. The Reflect object is an ordinary
object.
The Reflect object is not a function object. It does not have a [[Construct]]
internal method; it is not possible to use the Reflect object as a constructor
with the new operator. The Reflect object also does not have a [[Call]]
internal method; it is not possible to invoke the Reflect object as a
function.
---*/
assert.sameValue(typeof Reflect, 'object', '`typeof Reflect` is `"object"`');
// Reflect is not callable
assert.throws(TypeError, function() {
Reflect();
});
// Reflect doesn't have a constructor
assert.throws(TypeError, function() {
new Reflect();
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Reflect.apply is configurable, writable and not enumerable.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'apply');
verifyWritable(Reflect, 'apply');
verifyConfigurable(Reflect, 'apply');

View File

@ -0,0 +1,39 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Return abrupt if argumentsList is not an ArrayLike object.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
2. Let args be CreateListFromArrayLike(argumentsList).
3. ReturnIfAbrupt(args).
...
7.3.17 CreateListFromArrayLike (obj [, elementTypes] )
...
3. If Type(obj) is not Object, throw a TypeError exception.
4. Let len be ToLength(Get(obj, "length")).
5. ReturnIfAbrupt(len).
...
---*/
function fn() {}
var o = {};
Object.defineProperty(o, 'length', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.apply(fn, 1, o);
});
assert.throws(TypeError, function() {
Reflect.apply(fn, 1, 1);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Call target with thisArgument and argumentsList
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
4. Perform PrepareForTailCall().
5. Return Call(target, thisArgument, args).
---*/
var o = {};
var count = 0;
var results, args;
function fn() {
count++;
results = {
thisArg: this,
args: arguments
};
}
Reflect.apply(fn, o, ['arg1', 2, , null]);
assert.sameValue(count, 1, 'Called target once');
assert.sameValue(results.thisArg, o, 'Called target with `o` as `this` object');
assert.sameValue(results.args.length, 4, 'Called target with 4 arguments');
assert.sameValue(results.args[0], 'arg1');
assert.sameValue(results.args[1], 2);
assert.sameValue(results.args[2], undefined);
assert.sameValue(results.args[3], null);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Reflect.apply.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.apply.length, 3,
'The value of `Reflect.apply.length` is `3`'
);
verifyNotEnumerable(Reflect.apply, 'length');
verifyNotWritable(Reflect.apply, 'length');
verifyConfigurable(Reflect.apply, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Reflect.apply.name value and property descriptor
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.apply.name, 'apply',
'The value of `Reflect.apply.name` is `"apply"`'
);
verifyNotEnumerable(Reflect.apply, 'name');
verifyNotWritable(Reflect.apply, 'name');
verifyConfigurable(Reflect.apply, 'name');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Return target result
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
4. Perform PrepareForTailCall().
5. Return Call(target, thisArgument, args).
---*/
var o = {};
function fn() {
return o;
}
var result = Reflect.apply(fn, 1, []);
assert.sameValue(result, o);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.1
description: >
Throws a TypeError if `target` is not callable.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
1. If IsCallable(target) is false, throw a TypeError exception.
...
7.2.3 IsCallable ( argument )
1. ReturnIfAbrupt(argument).
2. If Type(argument) is not Object, return false.
3. If argument has a [[Call]] internal method, return true.
4. Return false.
---*/
assert.throws(TypeError, function() {
Reflect.apply(1, 1, []);
});
assert.throws(TypeError, function() {
Reflect.apply(null, 1, []);
});
assert.throws(TypeError, function() {
Reflect.apply({}, 1, []);
});

View File

@ -0,0 +1,39 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Return abrupt if argumentsList is not an ArrayLike object.
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
...
4. Let args be CreateListFromArrayLike(argumentsList).
5. ReturnIfAbrupt(args).
...
7.3.17 CreateListFromArrayLike (obj [, elementTypes] )
...
3. If Type(obj) is not Object, throw a TypeError exception.
4. Let len be ToLength(Get(obj, "length")).
5. ReturnIfAbrupt(len).
...
---*/
function fn() {}
var o = {};
Object.defineProperty(o, 'length', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.construct(fn, o);
});
assert.throws(TypeError, function() {
Reflect.construct(fn, 1);
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Reflect.construct is configurable, writable and not enumerable.
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'construct');
verifyWritable(Reflect, 'construct');
verifyConfigurable(Reflect, 'construct');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Reflect.construct.length value and property descriptor
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
The length property of the construct function is 2.
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.construct.length, 2,
'The value of `Reflect.construct.length` is `2`'
);
verifyNotEnumerable(Reflect.construct, 'length');
verifyNotWritable(Reflect.construct, 'length');
verifyConfigurable(Reflect.construct, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Reflect.construct.name value and property descriptor
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.construct.name, 'construct',
'The value of `Reflect.construct.name` is `"construct"`'
);
verifyNotEnumerable(Reflect.construct, 'name');
verifyNotWritable(Reflect.construct, 'name');
verifyConfigurable(Reflect.construct, 'name');

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Throws a TypeError if `newTarget` is not a constructor.
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
...
2. If newTarget is not present, let newTarget be target.
3. Else, if IsConstructor(newTarget) is false, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.construct(function() {}, [], 1);
});
assert.throws(TypeError, function() {
Reflect.construct(function() {}, [], null);
});
assert.throws(TypeError, function() {
Reflect.construct(function() {}, [], {});
});
assert.throws(TypeError, function() {
Reflect.construct(function() {}, [], Date.now);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Return target result using newTarget argument.
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
...
2. If newTarget is not present, let newTarget be target.
...
6. Return Construct(target, args, newTarget).
---*/
var o = {};
var internPrototype;
function fn() {
this.o = o;
internPrototype = Object.getPrototypeOf(this);
}
var result = Reflect.construct(fn, [], Array);
assert.sameValue(Object.getPrototypeOf(result), Array.prototype);
assert.sameValue(
internPrototype, Array.prototype,
'prototype of this from within the constructor function is Array.prototype'
);
assert.sameValue(result.o, o);

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Return target result
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
...
2. If newTarget is not present, let newTarget be target.
...
6. Return Construct(target, args, newTarget).
---*/
var o = {};
function fn() {
this.o = o;
}
var result = Reflect.construct(fn, []);
assert.sameValue(result.o, o);
assert(result instanceof fn);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Throws a TypeError if `target` is not a constructor.
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
1. If IsConstructor(target) is false, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Reflect.construct(1, []);
});
assert.throws(TypeError, function() {
Reflect.construct(null, []);
});
assert.throws(TypeError, function() {
Reflect.construct({}, []);
});
assert.throws(TypeError, function() {
Reflect.construct(Date.now, []);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.2
description: >
Construct with given argumentsList
info: >
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
...
2. If newTarget is not present, let newTarget be target.
...
6. Return Construct(target, args, newTarget).
---*/
function fn() {
this.args = arguments;
}
var result = Reflect.construct(fn, [42, 'Mike', 'Leo']);
assert.sameValue(result.args.length, 3, 'result.args.length');
assert.sameValue(result.args[0], 42);
assert.sameValue(result.args[1], 'Mike');
assert.sameValue(result.args[2], 'Leo');

View File

@ -0,0 +1,39 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Define properties from the attributes object.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
6. Return target.[[DefineOwnProperty]](key, desc).
includes: [propertyHelper.js]
---*/
var o = {};
var desc;
Reflect.defineProperty(o, 'p1', {
value: 42,
writable: true,
enumerable: true
});
assert.sameValue(o.p1, 42);
verifyWritable(o, 'p1');
verifyNotConfigurable(o, 'p1');
verifyEnumerable(o, 'p1');
var f1 = function() {};
var f2 = function() {};
Reflect.defineProperty(o, 'p2', {
get: f1,
set: f2
});
desc = Object.getOwnPropertyDescriptor(o, 'p2');
assert.sameValue(desc.get, f1);
assert.sameValue(desc.set, f2);

View File

@ -0,0 +1,53 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Define symbol properties.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
features: [Symbol]
---*/
var o = {};
var desc;
var s1 = Symbol('1');
Reflect.defineProperty(o, s1, {
value: 42,
writable: true,
enumerable: true
});
assert.sameValue(o[s1], 42);
desc = Object.getOwnPropertyDescriptor(o, s1);
assert.sameValue(desc.writable, true);
assert.sameValue(desc.configurable, false);
assert.sameValue(desc.enumerable, true);
var s2 = Symbol('2');
var f1 = function() {};
var f2 = function() {};
Reflect.defineProperty(o, s2, {
get: f1,
set: f2
});
desc = Object.getOwnPropertyDescriptor(o, s2);
assert.sameValue(desc.get, f1);
assert.sameValue(desc.set, f2);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Reflect.defineProperty is configurable, writable and not enumerable.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'defineProperty');
verifyWritable(Reflect, 'defineProperty');
verifyConfigurable(Reflect, 'defineProperty');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Reflect.defineProperty.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.defineProperty.length, 3,
'The value of `Reflect.defineProperty.length` is `3`'
);
verifyNotEnumerable(Reflect.defineProperty, 'length');
verifyNotWritable(Reflect.defineProperty, 'length');
verifyConfigurable(Reflect.defineProperty, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Reflect.defineProperty.name value and property descriptor
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.defineProperty.name, 'defineProperty',
'The value of `Reflect.defineProperty.name` is `"defineProperty"`'
);
verifyNotEnumerable(Reflect.defineProperty, 'name');
verifyNotWritable(Reflect.defineProperty, 'name');
verifyConfigurable(Reflect.defineProperty, 'name');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Return abrupt from ToPropertyDescriptor(attributes).
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
4. Let desc be ToPropertyDescriptor(attributes).
5. ReturnIfAbrupt(desc).
...
---*/
var attributes = {};
Object.defineProperty(attributes, 'enumerable', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.defineProperty({}, 'a', attributes);
});

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.defineProperty({}, p);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Return abrupt result on defining a property.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
6. Return target.[[DefineOwnProperty]](key, desc).
...
9.1.6.1 OrdinaryDefineOwnProperty (O, P, Desc)
1. Let current be O.[[GetOwnProperty]](P).
2. ReturnIfAbrupt(current).
...
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
defineProperty: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.defineProperty(p, 'p1', {});
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Return boolean result of the property definition.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
...
6. Return target.[[DefineOwnProperty]](key, desc).
---*/
var o = {};
o.p1 = 'foo';
assert.sameValue(Reflect.defineProperty(o, 'p1', {}), true);
assert.sameValue(o.hasOwnProperty('p1'), true);
assert.sameValue(Reflect.defineProperty(o, 'p2', {value: 42}), true);
assert.sameValue(o.hasOwnProperty('p2'), true);
Object.freeze(o);
assert.sameValue(Reflect.defineProperty(o, 'p2', {value: 43}), false);
assert.sameValue(o.p2, 42);
assert.sameValue(Reflect.defineProperty(o, 'p3', {}), false);
assert.sameValue(o.hasOwnProperty('p4'), false);
assert.sameValue(Reflect.defineProperty(o, 'p4', {value: 1}), false);
assert.sameValue(o.hasOwnProperty('p4'), false);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.defineProperty(1, 'p', {});
});
assert.throws(TypeError, function() {
Reflect.defineProperty(null, 'p', {});
});
assert.throws(TypeError, function() {
Reflect.defineProperty(undefined, 'p', {});
});
assert.throws(TypeError, function() {
Reflect.defineProperty('', 'p', {});
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.3
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.defineProperty(Symbol(1), 'p', {});
});

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Delete property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
4. Return target.[[Delete]](key).
---*/
var o = {
prop: 42
};
Reflect.deleteProperty(o, 'prop');
assert.sameValue(o.hasOwnProperty('prop'), false);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Delete a symbol property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
features: [Symbol]
---*/
var s = Symbol('1');
var o = {};
o[s] = 42;
Reflect.deleteProperty(o, s);
assert.sameValue(o.hasOwnProperty(s), false);
assert.sameValue(o[s], undefined);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Reflect.deleteProperty is configurable, writable and not enumerable.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'deleteProperty');
verifyWritable(Reflect, 'deleteProperty');
verifyConfigurable(Reflect, 'deleteProperty');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Reflect.deleteProperty.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.deleteProperty.length, 2,
'The value of `Reflect.deleteProperty.length` is `2`'
);
verifyNotEnumerable(Reflect.deleteProperty, 'length');
verifyNotWritable(Reflect.deleteProperty, 'length');
verifyConfigurable(Reflect.deleteProperty, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Reflect.deleteProperty.name value and property descriptor
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.deleteProperty.name, 'deleteProperty',
'The value of `Reflect.deleteProperty.name` is `"deleteProperty"`'
);
verifyNotEnumerable(Reflect.deleteProperty, 'name');
verifyNotWritable(Reflect.deleteProperty, 'name');
verifyConfigurable(Reflect.deleteProperty, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.deleteProperty({}, p);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Return abrupt result from deleting a property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
6. Return target.[[DefineOwnProperty]](key, desc).
...
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
deleteProperty: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.deleteProperty(p, 'p1');
});

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Return boolean result.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
4. Return target.[[Delete]](key).
---*/
var o = {};
o.p1 = 'foo';
assert.sameValue(Reflect.deleteProperty(o, 'p1'), true);
assert.sameValue(o.hasOwnProperty('p1'), false);
o.p2 = 'foo';
Object.freeze(o);
assert.sameValue(Reflect.deleteProperty(o, 'p2'), false);
assert.sameValue(o.hasOwnProperty('p2'), true);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.deleteProperty(1, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty(null, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty(undefined, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty('', 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.deleteProperty(Symbol(1), 'p');
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2015 Leonardo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Returned iterator does not iterate over symbol properties.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
features: [Symbol]
---*/
var iter, step;
var s = Symbol('1');
var o = {
'a': 1,
'b': 1
};
o[s] = 1;
iter = Reflect.enumerate(o);
step = iter.next();
assert.sameValue(step.value, 'a');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'b');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, true);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Reflect.enumerate is configurable, writable and not enumerable.
info: >
26.1.5 Reflect.enumerate ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'enumerate');
verifyWritable(Reflect, 'enumerate');
verifyConfigurable(Reflect, 'enumerate');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Reflect.enumerate.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.enumerate.length, 1,
'The value of `Reflect.enumerate.length` is `1`'
);
verifyNotEnumerable(Reflect.enumerate, 'length');
verifyNotWritable(Reflect.enumerate, 'length');
verifyConfigurable(Reflect.enumerate, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Reflect.enumerate.name value and property descriptor
info: >
26.1.5 Reflect.enumerate ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.enumerate.name, 'enumerate',
'The value of `Reflect.enumerate.name` is `"enumerate"`'
);
verifyNotEnumerable(Reflect.enumerate, 'name');
verifyNotWritable(Reflect.enumerate, 'name');
verifyConfigurable(Reflect.enumerate, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Return abrupt result.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
enumerate: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.enumerate(p);
});

View File

@ -0,0 +1,62 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Return an iterator.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
---*/
var iter, step;
var arr = ['a', 'b', 'c'];
iter = Reflect.enumerate(arr);
step = iter.next();
assert.sameValue(step.value, '0');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, '1');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, '2');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, true);
var o = {
'a': 42,
'b': 43,
'c': 44
};
Object.defineProperty(o, 'd', {
enumerable: false,
value: 45
});
iter = Reflect.enumerate(o);
step = iter.next();
assert.sameValue(step.value, 'a');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'b');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'c');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, true);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.5 Reflect.enumerate ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.enumerate(1);
});
assert.throws(TypeError, function() {
Reflect.enumerate(null);
});
assert.throws(TypeError, function() {
Reflect.enumerate(undefined);
});
assert.throws(TypeError, function() {
Reflect.enumerate('');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.5 Reflect.enumerate ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.enumerate(Symbol(1), 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Reflect.get is configurable, writable and not enumerable.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'get');
verifyWritable(Reflect, 'get');
verifyConfigurable(Reflect, 'get');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Reflect.get.length value and property descriptor
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
The length property of the get function is 2.
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.get.length, 2,
'The value of `Reflect.get.length` is `2`'
);
verifyNotEnumerable(Reflect.get, 'length');
verifyNotWritable(Reflect.get, 'length');
verifyConfigurable(Reflect.get, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Reflect.get.name value and property descriptor
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.get.name, 'get',
'The value of `Reflect.get.name` is `"get"`'
);
verifyNotEnumerable(Reflect.get, 'name');
verifyNotWritable(Reflect.get, 'name');
verifyConfigurable(Reflect.get, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.get({}, p);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Return abrupt result from get a property value.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
...
5. Return target.[[Get]](key, receiver).
---*/
var o1 = {};
Object.defineProperty(o1, 'p1', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.get(o1, 'p1');
});
// Abrupt from the prototype property
var o2 = Object.create(o1);
assert.throws(Test262Error, function() {
Reflect.get(o2, 'p1');
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Return value from a receiver.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
...
4. If receiver is not present, then
a. Let receiver be target.
5. Return target.[[Get]](key, receiver).
9.1.8 [[Get]] (P, Receiver)
...
2. Let desc be O.[[GetOwnProperty]](P).
3. ReturnIfAbrupt(desc).
4. If desc is undefined, then
a. Let parent be O.[[GetPrototypeOf]]().
b. ReturnIfAbrupt(parent).
c. If parent is null, return undefined.
d. Return parent.[[Get]](P, Receiver).
5. If IsDataDescriptor(desc) is true, return desc.[[Value]].
6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be
desc.[[Get]].
7. If getter is undefined, return undefined.
8. Return Call(getter, Receiver).
---*/
var o1 = {};
var receiver = {
y: 42
};
Object.defineProperty(o1, 'x', {
get: function() {
return this.y;
}
});
assert.sameValue(
Reflect.get(o1, 'x', receiver), 42,
'Return own property value using a receiver'
);
var o2 = Object.create(o1);
assert.sameValue(
Reflect.get(o2, 'x', receiver), 42,
'Return prototype property value using a receiver'
);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Return value where property key is a symbol.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
features: [Symbol]
---*/
var o = {};
var s = Symbol('1');
o[s] = 42;
assert.sameValue(Reflect.get(o, s), 42);

View File

@ -0,0 +1,67 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Return value.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
...
4. If receiver is not present, then
a. Let receiver be target.
5. Return target.[[Get]](key, receiver).
9.1.8 [[Get]] (P, Receiver)
...
2. Let desc be O.[[GetOwnProperty]](P).
3. ReturnIfAbrupt(desc).
4. If desc is undefined, then
a. Let parent be O.[[GetPrototypeOf]]().
b. ReturnIfAbrupt(parent).
c. If parent is null, return undefined.
d. Return parent.[[Get]](P, Receiver).
5. If IsDataDescriptor(desc) is true, return desc.[[Value]].
6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be
desc.[[Get]].
7. If getter is undefined, return undefined.
8. Return Call(getter, Receiver).
---*/
var o = {};
o.p1 = 'value 1';
assert.sameValue(
Reflect.get(o, 'p1'), 'value 1',
'Return value from data descriptor'
);
Object.defineProperty(o, 'p2', {
get: undefined
});
assert.sameValue(
Reflect.get(o, 'p2'), undefined,
'Return undefined if getter is undefined'
);
Object.defineProperty(o, 'p3', {
get: function() {
return 'foo';
}
});
assert.sameValue(
Reflect.get(o, 'p3'), 'foo',
'Return Call(getter, Receiver)'
);
var o2 = Object.create({p: 42});
assert.sameValue(
Reflect.get(o2, 'p'), 42,
'Return value from prototype without own property.'
);
assert.sameValue(
Reflect.get(o2, 'u'), undefined,
'Return undefined without property on the object and its prototype'
);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.get(1, 'p');
});
assert.throws(TypeError, function() {
Reflect.get(null, 'p');
});
assert.throws(TypeError, function() {
Reflect.get(undefined, 'p');
});
assert.throws(TypeError, function() {
Reflect.get('', 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.6
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.get(Symbol(1), 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Reflect.getOwnPropertyDescriptor is configurable, writable and not enumerable.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'getOwnPropertyDescriptor');
verifyWritable(Reflect, 'getOwnPropertyDescriptor');
verifyConfigurable(Reflect, 'getOwnPropertyDescriptor');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Reflect.getOwnPropertyDescriptor.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.getOwnPropertyDescriptor.length, 2,
'The value of `Reflect.getOwnPropertyDescriptor.length` is `2`'
);
verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'length');
verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'length');
verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Reflect.getOwnPropertyDescriptor.name value and property descriptor
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.getOwnPropertyDescriptor.name, 'getOwnPropertyDescriptor',
'The value of `Reflect.getOwnPropertyDescriptor.name` is `"getOwnPropertyDescriptor"`'
);
verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'name');
verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'name');
verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.getOwnPropertyDescriptor({}, p);
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return abrupt result from getting the property descriptor.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
4. Let desc be target.[[GetOwnProperty]](key).
5. ReturnIfAbrupt(desc).
...
features: [Proxy]
---*/
var o1 = {};
var p = new Proxy(o1, {
getOwnPropertyDescriptor: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.getOwnPropertyDescriptor(p, 'p1');
});

View File

@ -0,0 +1,56 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return a property descriptor object as an accessor descriptor.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
4. Let desc be target.[[GetOwnProperty]](key).
5. ReturnIfAbrupt(desc).
6. Return FromPropertyDescriptor(desc).
6.2.4.4 FromPropertyDescriptor ( Desc )
...
2. Let obj be ObjectCreate(%ObjectPrototype%).
...
4. If Desc has a [[Value]] field, then
a. Perform CreateDataProperty(obj, "value", Desc.[[Value]]).
5. If Desc has a [[Writable]] field, then
a. Perform CreateDataProperty(obj, "writable", Desc.[[Writable]]).
6. If Desc has a [[Get]] field, then
a. Perform CreateDataProperty(obj, "get", Desc.[[Get]]).
7. If Desc has a [[Set]] field, then
a. Perform CreateDataProperty(obj, "set", Desc.[[Set]])
8. If Desc has an [[Enumerable]] field, then
a. Perform CreateDataProperty(obj, "enumerable", Desc.[[Enumerable]]).
9. If Desc has a [[Configurable]] field, then
a. Perform CreateDataProperty(obj , "configurable", Desc.[[Configurable]]).
...
11. Return obj.
includes: [compareArray.js]
---*/
var o1 = {};
var fn = function() {};
Object.defineProperty(o1, 'p', {
get: fn,
configurable: true
});
var result = Reflect.getOwnPropertyDescriptor(o1, 'p');
assert(
compareArray(
Object.keys(result),
['get', 'set', 'enumerable', 'configurable']
)
);
assert.sameValue(result.enumerable, false);
assert.sameValue(result.configurable, true);
assert.sameValue(result.get, fn);
assert.sameValue(result.set, undefined);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return a property descriptor object as a data descriptor.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
4. Let desc be target.[[GetOwnProperty]](key).
5. ReturnIfAbrupt(desc).
6. Return FromPropertyDescriptor(desc).
includes: [compareArray.js]
---*/
var o1 = {
p: 'foo'
};
var result = Reflect.getOwnPropertyDescriptor(o1, 'p');
assert(
compareArray(
Object.keys(result),
['value', 'writable', 'enumerable', 'configurable']
)
);
assert.sameValue(result.value, 'foo');
assert.sameValue(result.enumerable, true);
assert.sameValue(result.configurable, true);
assert.sameValue(result.writable, true);

View File

@ -0,0 +1,39 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Use a symbol value on property key.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
includes: [compareArray.js]
features: [Symbol]
---*/
var o = {};
var s = Symbol('42');
o[s] = 42;
var result = Reflect.getOwnPropertyDescriptor(o, s);
assert(
compareArray(
Object.keys(result),
['value', 'writable', 'enumerable', 'configurable']
)
);
assert.sameValue(result.value, 42);
assert.sameValue(result.enumerable, true);
assert.sameValue(result.configurable, true);
assert.sameValue(result.writable, true);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.getOwnPropertyDescriptor(1, 'p');
});
assert.throws(TypeError, function() {
Reflect.getOwnPropertyDescriptor(null, 'p');
});
assert.throws(TypeError, function() {
Reflect.getOwnPropertyDescriptor(undefined, 'p');
});
assert.throws(TypeError, function() {
Reflect.getOwnPropertyDescriptor('', 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.getOwnPropertyDescriptor(Symbol(1), 'p');
});

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 Leonardo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return undefined for an non existing own property.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
4. Let desc be target.[[GetOwnProperty]](key).
5. ReturnIfAbrupt(desc).
6. Return FromPropertyDescriptor(desc).
6.2.4.4 FromPropertyDescriptor ( Desc )
1. If Desc is undefined, return undefined.
---*/
var o = Object.create({p: 1});
var result = Reflect.getOwnPropertyDescriptor(o, 'p');
assert.sameValue(result, undefined);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.7
description: >
Return undefined for an undefined property.
info: >
26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
...
4. Let desc be target.[[GetOwnProperty]](key).
5. ReturnIfAbrupt(desc).
6. Return FromPropertyDescriptor(desc).
6.2.4.4 FromPropertyDescriptor ( Desc )
1. If Desc is undefined, return undefined.
---*/
var result = Reflect.getOwnPropertyDescriptor({}, undefined);
assert.sameValue(result, undefined);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Reflect.getPrototypeOf is configurable, writable and not enumerable.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'getPrototypeOf');
verifyWritable(Reflect, 'getPrototypeOf');
verifyConfigurable(Reflect, 'getPrototypeOf');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Reflect.getPrototypeOf.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.getPrototypeOf.length, 1,
'The value of `Reflect.getPrototypeOf.length` is `1`'
);
verifyNotEnumerable(Reflect.getPrototypeOf, 'length');
verifyNotWritable(Reflect.getPrototypeOf, 'length');
verifyConfigurable(Reflect.getPrototypeOf, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Reflect.getPrototypeOf.name value and property descriptor
info: >
26.1.8 Reflect.getPrototypeOf ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.getPrototypeOf.name, 'getPrototypeOf',
'The value of `Reflect.getPrototypeOf.name` is `"getPrototypeOf"`'
);
verifyNotEnumerable(Reflect.getPrototypeOf, 'name');
verifyNotWritable(Reflect.getPrototypeOf, 'name');
verifyConfigurable(Reflect.getPrototypeOf, 'name');

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Return null prototype.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
...
2. Return target.[[GetPrototypeOf]]().
---*/
var o = Object.create(null);
assert.sameValue(Reflect.getPrototypeOf(o), null);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Return abrupt result from getting the prototype.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
...
2. Return target.[[GetPrototypeOf]]().
...
features: [Proxy]
---*/
var o1 = {};
var p = new Proxy(o1, {
getPrototypeOf: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.getPrototypeOf(p);
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Returns the internal [[Prototype]] object.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
...
2. Return target.[[GetPrototypeOf]]().
---*/
var o = {};
assert.sameValue(
Reflect.getPrototypeOf(o), Object.prototype,
'return default prototypes'
);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Skip own properties to return the internal [[Prototype]] object.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
...
2. Return target.[[GetPrototypeOf]]().
---*/
var valid = {};
var o = Object.create(valid, {
prototype: {value: 'invalid', enumerable: true}
});
assert.sameValue(
Reflect.getPrototypeOf(o), valid,
'skip own properties'
);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.8 Reflect.getPrototypeOf ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.getPrototypeOf(1);
});
assert.throws(TypeError, function() {
Reflect.getPrototypeOf(null);
});
assert.throws(TypeError, function() {
Reflect.getPrototypeOf(undefined);
});
assert.throws(TypeError, function() {
Reflect.getPrototypeOf('');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.8
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.8 Reflect.getPrototypeOf ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.getPrototypeOf(Symbol(1));
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Reflect.has is configurable, writable and not enumerable.
info: >
26.1.9 Reflect.has ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'has');
verifyWritable(Reflect, 'has');
verifyConfigurable(Reflect, 'has');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Reflect.has.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.has.length, 2,
'The value of `Reflect.has.length` is `2`'
);
verifyNotEnumerable(Reflect.has, 'length');
verifyNotWritable(Reflect.has, 'length');
verifyConfigurable(Reflect.has, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Reflect.has.name value and property descriptor
info: >
26.1.9 Reflect.has ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.has.name, 'has',
'The value of `Reflect.has.name` is `"has"`'
);
verifyNotEnumerable(Reflect.has, 'name');
verifyNotWritable(Reflect.has, 'name');
verifyConfigurable(Reflect.has, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.9 Reflect.has ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.has({}, p);
});

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Return abrupt result.
info: >
26.1.9 Reflect.has ( target, propertyKey )
...
4. Return target.[[HasProperty]](key).
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
has: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.has(p, 'p1');
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Return boolean value.
info: >
26.1.9 Reflect.has ( target, propertyKey )
...
4. Return target.[[HasProperty]](key).
9.1.7.1 OrdinaryHasProperty (O, P)
...
2. Let hasOwn be OrdinaryGetOwnProperty(O, P).
3. If hasOwn is not undefined, return true.
4. Let parent be O.[[GetPrototypeOf]]().
5. ReturnIfAbrupt(parent).
6. If parent is not null, then
a. Return parent.[[HasProperty]](P).
7. Return false.
---*/
var o1 = {
p: 42
};
assert.sameValue(Reflect.has(o1, 'p'), true, 'true from own property');
assert.sameValue(
Reflect.has(o1, 'z'), false,
'false when property is not present'
);
var o2 = Object.create({p: 42});
assert.sameValue(Reflect.has(o2, 'p'), true, 'true from a prototype property');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Return boolean value from a projectKey as a Symbol
info: >
26.1.9 Reflect.has ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
features: [Symbol]
---*/
var o = {};
var s1 = Symbol('1');
o[s1] = 42;
var s2 = Symbol('1');
assert.sameValue(Reflect.has(o, s1), true, 'true from own property');
assert.sameValue(
Reflect.has(o, s2), false,
'false when property is not present'
);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.9 Reflect.has ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.has(1, 'p');
});
assert.throws(TypeError, function() {
Reflect.has(null, 'p');
});
assert.throws(TypeError, function() {
Reflect.has(undefined, 'p');
});
assert.throws(TypeError, function() {
Reflect.has('', 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.9
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.9 Reflect.has ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.has(Symbol(1), 'p');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Reflect.isExtensible is configurable, writable and not enumerable.
info: >
26.1.10 Reflect.isExtensible (target)
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'isExtensible');
verifyWritable(Reflect, 'isExtensible');
verifyConfigurable(Reflect, 'isExtensible');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Reflect.isExtensible.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.isExtensible.length, 1,
'The value of `Reflect.isExtensible.length` is `1`'
);
verifyNotEnumerable(Reflect.isExtensible, 'length');
verifyNotWritable(Reflect.isExtensible, 'length');
verifyConfigurable(Reflect.isExtensible, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Reflect.isExtensible.name value and property descriptor
info: >
26.1.10 Reflect.isExtensible (target)
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.isExtensible.name, 'isExtensible',
'The value of `Reflect.isExtensible.name` is `"isExtensible"`'
);
verifyNotEnumerable(Reflect.isExtensible, 'name');
verifyNotWritable(Reflect.isExtensible, 'name');
verifyConfigurable(Reflect.isExtensible, 'name');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Return abrupt result.
info: >
26.1.10 Reflect.isExtensible (target)
...
2. Return target.[[IsExtensible]]().
features: [Proxy]
---*/
var o1 = {};
var p = new Proxy(o1, {
isExtensible: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.isExtensible(p);
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Returns the boolean result.
info: >
26.1.10 Reflect.isExtensible (target)
...
2. Return target.[[IsExtensible]]().
---*/
var o = {};
assert.sameValue(Reflect.isExtensible(o), true);
Object.preventExtensions(o);
assert.sameValue(Reflect.isExtensible(o), false);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.10 Reflect.isExtensible (target)
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.isExtensible(1);
});
assert.throws(TypeError, function() {
Reflect.isExtensible(null);
});
assert.throws(TypeError, function() {
Reflect.isExtensible(undefined);
});
assert.throws(TypeError, function() {
Reflect.isExtensible('');
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.10
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.10 Reflect.isExtensible (target)
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.isExtensible(Symbol(1));
});

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1
description: >
The value of the [[Prototype]] internal slot of the Reflect object
is the intrinsic object %ObjectPrototype% (19.1.3).
---*/
assert.sameValue(
Object.getPrototypeOf(Reflect),
Object.prototype,
'`Object.getPrototypeOf(Reflect)` returns `Object.prototype`'
);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Reflect.ownKeys.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.ownKeys.length, 1,
'The value of `Reflect.ownKeys.length` is `1`'
);
verifyNotEnumerable(Reflect.ownKeys, 'length');
verifyNotWritable(Reflect.ownKeys, 'length');
verifyConfigurable(Reflect.ownKeys, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Reflect.ownKeys.name value and property descriptor
info: >
26.1.11 Reflect.ownKeys ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.ownKeys.name, 'ownKeys',
'The value of `Reflect.ownKeys.name` is `"ownKeys"`'
);
verifyNotEnumerable(Reflect.ownKeys, 'name');
verifyNotWritable(Reflect.ownKeys, 'name');
verifyConfigurable(Reflect.ownKeys, 'name');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Reflect.ownKeys is configurable, writable and not enumerable.
info: >
26.1.11 Reflect.ownKeys ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'ownKeys');
verifyWritable(Reflect, 'ownKeys');
verifyConfigurable(Reflect, 'ownKeys');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Return abrupt result from target.[[OwnPropertyKeys]]()
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
...
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
ownKeys: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.ownKeys(p);
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Returns target's own property keys only, ignore prototype keys.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
includes: [compareArray.js]
---*/
var proto = {
foo: 1
};
var o = Object.create(proto);
o.p1 = 42;
o.p2 = 43;
o.p3 = 44;
assert(
compareArray(Reflect.ownKeys(o), ['p1', 'p2', 'p3']),
'return object own keys'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.11
description: >
Returns empty array when target has now own properties.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
includes: [compareArray.js]
---*/
assert(compareArray(Reflect.ownKeys({}), []));
var o = {d: 42};
delete o.d;
assert(compareArray(Reflect.ownKeys(o), []));

Some files were not shown because too many files have changed in this diff Show More