From 0893865705a74c1eacb8211ec21c189ebff24e11 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 11 Sep 2019 23:02:03 +0300 Subject: [PATCH] Add async generator default prototype tests (#2336) * Add default prototype test * Add cross-realm default prototype test --- .../async-generator/default-proto.js | 51 ++++++++++++++++++ .../async-generator/eval-body-proto-realm.js | 52 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 test/language/expressions/async-generator/default-proto.js create mode 100644 test/language/expressions/async-generator/eval-body-proto-realm.js diff --git a/test/language/expressions/async-generator/default-proto.js b/test/language/expressions/async-generator/default-proto.js new file mode 100644 index 0000000000..e76e4e2e57 --- /dev/null +++ b/test/language/expressions/async-generator/default-proto.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-asyncgenerator-definitions-evaluatebody +description: > + Default [[Prototype]] value derived from realm of the async generator function. +info: | + Runtime Semantics: EvaluateBody + + ... + 2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%", « ... »). + 3. Perform ! AsyncGeneratorStart(generator, FunctionBody). + 4. Return Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty }. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [async-iteration, Symbol] +---*/ + +var fn = async function* () {}; +var AsyncGeneratorPrototype = Object.getPrototypeOf(fn.prototype); + +fn.prototype = undefined; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is undefined'); + +fn.prototype = null; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is null'); + +fn.prototype = false; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Boolean'); + +fn.prototype = ''; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a String'); + +fn.prototype = Symbol(); +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Symbol'); + +fn.prototype = 1; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Number'); diff --git a/test/language/expressions/async-generator/eval-body-proto-realm.js b/test/language/expressions/async-generator/eval-body-proto-realm.js new file mode 100644 index 0000000000..78d3c681b4 --- /dev/null +++ b/test/language/expressions/async-generator/eval-body-proto-realm.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-asyncgenerator-definitions-evaluatebody +description: > + Default [[Prototype]] value derived from realm of the async generator function. +info: | + Runtime Semantics: EvaluateBody + + ... + 2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%", « ... »). + 3. Perform ! AsyncGeneratorStart(generator, FunctionBody). + 4. Return Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty }. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [async-iteration, cross-realm, Symbol] +---*/ + +var other = $262.createRealm().global; +var fn = other.eval('(0, async function* () {})'); +var AsyncGeneratorPrototype = Object.getPrototypeOf(fn.prototype); + +fn.prototype = undefined; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is undefined'); + +fn.prototype = null; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is null'); + +fn.prototype = true; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Boolean'); + +fn.prototype = 'str'; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a String'); + +fn.prototype = Symbol(); +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Symbol'); + +fn.prototype = 0; +assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Number');