diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/GeneratorFunction')
27 files changed, 713 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/browser.js b/js/src/tests/test262/built-ins/GeneratorFunction/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/browser.js diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/extensibility.js b/js/src/tests/test262/built-ins/GeneratorFunction/extensibility.js new file mode 100644 index 0000000000..3a69585d74 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/extensibility.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-properties-of-the-generatorfunction-constructor +description: Object extensibility +info: | + The value of the [[Extensible]] internal slot of the GeneratorFunction + constructor is true. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert(Object.isExtensible(GeneratorFunction)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/has-instance.js b/js/src/tests/test262/built-ins/GeneratorFunction/has-instance.js new file mode 100644 index 0000000000..fe5fab5430 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/has-instance.js @@ -0,0 +1,36 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2 +description: > + Generator function instances are correctly reported as instances of the + GeneratorFunction intrinsic. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +function* gDecl() {} +var gExpr = function*() {}; + +assert( + gDecl instanceof GeneratorFunction, + 'Generators created via GeneratorDeclaration syntax are proper instances of GeneratorFunction' +); + +assert( + gExpr instanceof GeneratorFunction, + 'Generators created via GeneratorExpression syntax are proper instances of GeneratorFunction' +); + +assert( + new GeneratorFunction() instanceof GeneratorFunction, + 'Generators created via constructor invocation of GeneratorFunction are proper instances of GeneratorFunction' +); + +assert( + GeneratorFunction() instanceof GeneratorFunction, + 'Generators created via function invocation of GeneratorFunction are proper instances of GeneratorFunction' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-construct-throws.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-construct-throws.js new file mode 100644 index 0000000000..db16b01eb1 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-construct-throws.js @@ -0,0 +1,32 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generatorfunction +description: The instance created by GeneratorFunction is not a constructor +info: | + 25.2.1.1 GeneratorFunction ( p1, p2, … , pn, body ) + + ... + 3. Return ? CreateDynamicFunction(C, NewTarget, "generator", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction( constructor, newTarget, kind, args ) + + ... + 34. If kind is "generator", then + a. Let prototype be ObjectCreate(%GeneratorPrototype%). + b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor{[[Value]]: prototype, + [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}). + ... +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var instance = GeneratorFunction(); + +assert.throws(TypeError, function() { + new instance(); +}) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-length.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-length.js new file mode 100644 index 0000000000..3af90cc37b --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-length.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction +description: Definition of instance `length` property +info: | + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "generator", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction + + [...] + 26. Perform FunctionInitialize(F, Normal, parameters, body, scope). + [...] + + 9.2.4 FunctionInitialize + + [...] + 3. Perform ! DefinePropertyOrThrow(F, "length", + PropertyDescriptor{[[Value]]: len, [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true}). + [...] +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert.sameValue(GeneratorFunction().length, 0); +assert.sameValue(GeneratorFunction('').length, 0); +assert.sameValue(GeneratorFunction('x').length, 0); +assert.sameValue(GeneratorFunction('x', '').length, 1); +assert.sameValue(GeneratorFunction('x', 'y', '').length, 2); +assert.sameValue(GeneratorFunction('x, y', '').length, 2); + +verifyNotEnumerable(GeneratorFunction(), 'length'); +verifyNotWritable(GeneratorFunction(), 'length'); +verifyConfigurable(GeneratorFunction(), 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-name.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-name.js new file mode 100644 index 0000000000..dd3e2a19d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-name.js @@ -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: 25.2.1.1 +description: Assignment of function `name` attribute +info: | + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "generator", args). + + ES6 19.2.1.1.1 + RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args) + + [...] + 29. Perform SetFunctionName(F, "anonymous"). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert.sameValue(GeneratorFunction().name, 'anonymous'); +verifyNotEnumerable(GeneratorFunction(), 'name'); +verifyNotWritable(GeneratorFunction(), 'name'); +verifyConfigurable(GeneratorFunction(), 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-prototype.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-prototype.js new file mode 100644 index 0000000000..a9886a15e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-prototype.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction +description: Definition of instance `prototype` property +info: | + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "generator", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction + + [...] + 27. If kind is "generator", then + a. Let prototype be ObjectCreate(%GeneratorPrototype%). + b. Perform DefinePropertyOrThrow(F, "prototype", + PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: false}). + [...] +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var instance = GeneratorFunction(); + +assert.sameValue(typeof instance.prototype, 'object'); +assert.sameValue( + Object.getPrototypeOf(instance.prototype), + Object.getPrototypeOf(instance).prototype +); + +verifyNotEnumerable(instance, 'prototype'); +verifyWritable(instance, 'prototype'); +verifyNotConfigurable(instance, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-restricted-properties.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-restricted-properties.js new file mode 100644 index 0000000000..73e7e8b9d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-restricted-properties.js @@ -0,0 +1,39 @@ +// 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 intrinsic function do not have + own properties "caller" or "arguments", but inherit them from + %FunctionPrototype%. +features: [generators] +---*/ + +var Generator = Object.getPrototypeOf(function*() {}); +var GeneratorFunction = Generator.constructor; +var generator = new GeneratorFunction(); + +assert.sameValue( + generator.hasOwnProperty('caller'), false, 'No "caller" own property' +); +assert.sameValue( + generator.hasOwnProperty('arguments'), false, 'No "arguments" own property' +); + +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 = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/instance-yield-expr-in-param.js b/js/src/tests/test262/built-ins/GeneratorFunction/instance-yield-expr-in-param.js new file mode 100644 index 0000000000..8c39db4657 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/instance-yield-expr-in-param.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction +description: Definition of instance `length` property +info: | + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "generator", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction + + [...] + 20. If kind is "generator", then + a. If parameters Contains YieldExpression is true, throw a SyntaxError + exception. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +// YieldExpression is permitted in function body. +GeneratorFunction('x = yield'); + +assert.throws(SyntaxError, function() { + GeneratorFunction('x = yield', ''); +}, 'YieldExpression not permitted generally'); + +var withinGenerator = function*() { + GeneratorFunction('x = yield', ''); +}; + +assert.throws(SyntaxError, function() { + withinGenerator().next(); +}, 'YieldExpression not permitted when calling context is a generator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-constructor-no-arguments.js b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-constructor-no-arguments.js new file mode 100644 index 0000000000..349607256d --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-constructor-no-arguments.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2 +description: > + When invoked via the constructor invocation pattern without arguments, the + GeneratorFunction intrinsic returns a valid generator with an empty body. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var g = new GeneratorFunction(); +var iter = g(); +var result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-multiple-arguments.js b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-multiple-arguments.js new file mode 100644 index 0000000000..0c3e42f932 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-multiple-arguments.js @@ -0,0 +1,27 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2 +description: > + When invoked via the function invocation pattern with multiple arguments, + the GeneratorFunction intrinsic creates a valid generator whose body is the + last argument evaluated as source code and whose formal parameters are + defined by the preceding arguments. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var g = GeneratorFunction('x', 'y', 'yield x + y;'); +var iter = g(2, 3); +var result; + +result = iter.next(); +assert.sameValue(result.value, 5, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Final result `value`'); +assert.sameValue(result.done, true, 'Final result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-no-arguments.js b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-no-arguments.js new file mode 100644 index 0000000000..822e582f71 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-no-arguments.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2 +description: > + When invoked via the function invocation pattern without arguments, the + GeneratorFunction intrinsic returns a valid generator with an empty body. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var g = GeneratorFunction(); +var iter = g(); +var result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-single-argument.js b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-single-argument.js new file mode 100644 index 0000000000..18bb186f56 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/invoked-as-function-single-argument.js @@ -0,0 +1,26 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2 +description: > + When invoked via the function invocation pattern with a single argument, + the GeneratorFunction intrinsic creates a valid generator whose body is the + first argument evaluated as source code. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +var g = GeneratorFunction('yield 1;'); +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Final result `value`'); +assert.sameValue(result.done, true, 'Final result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/is-a-constructor.js b/js/src/tests/test262/built-ins/GeneratorFunction/is-a-constructor.js new file mode 100644 index 0000000000..e28ffe8028 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The GeneratorFunction constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js, hidden-constructors.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(isConstructor(GeneratorFunction), true, 'isConstructor(GeneratorFunction) must return true'); +new GeneratorFunction(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/length.js b/js/src/tests/test262/built-ins/GeneratorFunction/length.js new file mode 100644 index 0000000000..578af8be55 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/length.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction.length +description: > + This is a data property with a value of 1. This property has the attributes { + [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert.sameValue(GeneratorFunction.length, 1); + +verifyNotEnumerable(GeneratorFunction, 'length'); +verifyNotWritable(GeneratorFunction, 'length'); +verifyConfigurable(GeneratorFunction, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/name.js b/js/src/tests/test262/built-ins/GeneratorFunction/name.js new file mode 100644 index 0000000000..3025416d2c --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-properties-of-the-generatorfunction-constructor +description: Function "name" property +info: | + The value of the name property of the GeneratorFunction is + "GeneratorFunction". + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. + + Unless otherwise specified, the name property of a built-in Function object, + if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert.sameValue(GeneratorFunction.name, 'GeneratorFunction'); + +verifyNotEnumerable(GeneratorFunction, 'name'); +verifyNotWritable(GeneratorFunction, 'name'); +verifyConfigurable(GeneratorFunction, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm-prototype.js b/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm-prototype.js new file mode 100644 index 0000000000..bfe460bcb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm-prototype.js @@ -0,0 +1,52 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-createdynamicfunction +description: > + While default [[Prototype]] value derives from realm of the newTarget, + "prototype" object inherits from %Object.prototype% of constructor's realm. +info: | + GeneratorFunction ( p1, p2, … , pn, body ) + + [...] + 3. Return ? CreateDynamicFunction(C, NewTarget, generator, args). + + CreateDynamicFunction ( constructor, newTarget, kind, args ) + + [...] + 18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). + 19. Let realmF be the current Realm Record. + 20. Let scope be realmF.[[GlobalEnv]]. + 21. Let F be ! OrdinaryFunctionCreate(proto, parameters, body, non-lexical-this, scope). + [...] + 23. If kind is generator, then + a. Let prototype be OrdinaryObjectCreate(%Generator.prototype%). + b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, + [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). + [...] + 30. Return F. +features: [generators, cross-realm, Reflect] +---*/ + +var realmA = $262.createRealm().global; +realmA.calls = 0; +var aGeneratorFunction = realmA.eval("(function* () {})").constructor; +var aGeneratorPrototype = Object.getPrototypeOf( + realmA.eval("(function* () {})").prototype +); + +var realmB = $262.createRealm().global; +var bGeneratorFunction = realmB.eval("(function* () {})").constructor; +var newTarget = new realmB.Function(); +newTarget.prototype = null; + +var fn = Reflect.construct(aGeneratorFunction, ["calls += 1;"], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), bGeneratorFunction.prototype); +assert.sameValue(Object.getPrototypeOf(fn.prototype), aGeneratorPrototype); + +var gen = fn(); +assert(gen instanceof realmA.Object); +gen.next(); +assert.sameValue(realmA.calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm.js new file mode 100644 index 0000000000..b24db90dc4 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/proto-from-ctor-realm.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 3. Return ? CreateDynamicFunction(C, NewTarget, "generator", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction + + [...] + 3. Else, + [...] + c. Let fallbackProto be "%Generator%". + [...] + 22. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [generators, cross-realm, Reflect] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; +var other = $262.createRealm().global; +var OtherGeneratorFunction = Object.getPrototypeOf( + other.eval('(0, function* () {})') +).constructor; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(GeneratorFunction, [], C); + +assert.sameValue(Object.getPrototypeOf(o), OtherGeneratorFunction.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..d8094e51af --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/Symbol.toStringTag.js @@ -0,0 +1,28 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "GeneratorFunction". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +es6id: 25.2.3.3 +includes: [propertyHelper.js] +features: [generators, Symbol.toStringTag] +---*/ + +var GeneratorFunctionPrototype = Object.getPrototypeOf(function*() {}); + +assert.sameValue( + GeneratorFunctionPrototype[Symbol.toStringTag], 'GeneratorFunction' +); + +verifyNotEnumerable(GeneratorFunctionPrototype, Symbol.toStringTag); +verifyNotWritable(GeneratorFunctionPrototype, Symbol.toStringTag); +verifyConfigurable(GeneratorFunctionPrototype, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/browser.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/constructor.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/constructor.js new file mode 100644 index 0000000000..2166e3dce1 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorfunction.prototype.constructor +description: > + `constructor` property of the GeneratorFunction.prototype object +info: | + The initial value of GeneratorFunction.prototype.constructor is the intrinsic + object %GeneratorFunction%. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert.sameValue(GeneratorFunction.prototype.constructor, GeneratorFunction); + +verifyNotEnumerable(GeneratorFunction.prototype, 'constructor'); +verifyNotWritable(GeneratorFunction.prototype, 'constructor'); +verifyConfigurable(GeneratorFunction.prototype, 'constructor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/extensibility.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/extensibility.js new file mode 100644 index 0000000000..dd1d470f02 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/extensibility.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-properties-of-the-generatorfunction-prototype-object +description: Object extensibility +info: | + The initial value of the [[Extensible]] internal slot of the + GeneratorFunction prototype object is true. +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +assert(Object.isExtensible(GeneratorFunction.prototype)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/not-callable.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/not-callable.js new file mode 100644 index 0000000000..2c7aac58ca --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/not-callable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-generatorfunction-prototype-object +description: > + %GeneratorFunction.prototype% is an ordinary non-callable object. +info: | + Properties of the GeneratorFunction Prototype Object + + The GeneratorFunction prototype object: + + [...] + * is an ordinary object. + * is not a function object and does not have an [[ECMAScriptCode]] internal slot + or any other of the internal slots listed in Table 28 or Table 74. +features: [generators] +---*/ + +var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {}); + +assert.sameValue(typeof GeneratorFunctionPrototype, "object"); +assert.throws(TypeError, function() { + GeneratorFunctionPrototype(); +}); + +assert(!GeneratorFunctionPrototype.hasOwnProperty("length"), "length"); +assert(!GeneratorFunctionPrototype.hasOwnProperty("name"), "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prop-desc.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prop-desc.js new file mode 100644 index 0000000000..5be780399b --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.5.1 +description: GeneratorFunction.prototype property descriptor +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor; + +verifyNotEnumerable(GeneratorFunction, 'prototype'); +verifyNotWritable(GeneratorFunction, 'prototype'); +verifyNotConfigurable(GeneratorFunction, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prototype.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prototype.js new file mode 100644 index 0000000000..66b18eb458 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/prototype.js @@ -0,0 +1,25 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.3.2 +description: > + The value of GeneratorFunction.prototype.prototype is the + %GeneratorPrototype% intrinsic object. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +var GeneratorFunctionPrototype = Object.getPrototypeOf(function*() {}); +assert.sameValue( + GeneratorFunctionPrototype.prototype, + Object.getPrototypeOf(function*() {}.prototype) +); + +verifyNotEnumerable(GeneratorFunctionPrototype, 'prototype'); +verifyNotWritable(GeneratorFunctionPrototype, 'prototype'); +verifyConfigurable(GeneratorFunctionPrototype, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/prototype/shell.js b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/GeneratorFunction/shell.js b/js/src/tests/test262/built-ins/GeneratorFunction/shell.js new file mode 100644 index 0000000000..7af18bddd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorFunction/shell.js @@ -0,0 +1,43 @@ +// GENERATED, DO NOT EDIT +// file: hidden-constructors.js +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Provides uniform access to built-in constructors that are not exposed to the global object. +defines: + - AsyncArrowFunction + - AsyncFunction + - AsyncGeneratorFunction + - GeneratorFunction +---*/ + +var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor; +var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; +var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} |