tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

eval-body-proto-realm.js (2116B)


      1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-asyncgenerator-definitions-evaluatebody
      5 description: >
      6  Default [[Prototype]] value derived from realm of the async generator function.
      7 info: |
      8  Runtime Semantics: EvaluateBody
      9 
     10  ...
     11  2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%", « ... »).
     12  3. Perform ! AsyncGeneratorStart(generator, FunctionBody).
     13  4. Return Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty }.
     14 
     15  OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
     16 
     17  ...
     18  2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
     19  3. Return ObjectCreate(proto, internalSlotsList).
     20 
     21  GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
     22 
     23  ...
     24  3. Let proto be ? Get(constructor, 'prototype').
     25  4. If Type(proto) is not Object, then
     26    a. Let realm be ? GetFunctionRealm(constructor).
     27    b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
     28  5. Return proto.
     29 features: [async-iteration, cross-realm, Symbol]
     30 ---*/
     31 
     32 var other = $262.createRealm().global;
     33 var fn = other.eval('(0, async function* () {})');
     34 var AsyncGeneratorPrototype = Object.getPrototypeOf(fn.prototype);
     35 
     36 fn.prototype = undefined;
     37 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is undefined');
     38 
     39 fn.prototype = null;
     40 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is null');
     41 
     42 fn.prototype = true;
     43 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Boolean');
     44 
     45 fn.prototype = 'str';
     46 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a String');
     47 
     48 fn.prototype = Symbol();
     49 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Symbol');
     50 
     51 fn.prototype = 0;
     52 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Number');
     53 
     54 reportCompare(0, 0);