tor-browser

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

proto-from-ctor-realm.js (1341B)


      1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-generatorfunction
      5 description: Default [[Prototype]] value derived from realm of the newTarget
      6 info: |
      7    [...]
      8    3. Return ? CreateDynamicFunction(C, NewTarget, "generator", args).
      9 
     10    19.2.1.1.1 Runtime Semantics: CreateDynamicFunction
     11 
     12    [...]
     13    3. Else,
     14       [...]
     15       c. Let fallbackProto be "%Generator%".
     16    [...]
     17    22. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
     18    [...]
     19 
     20    9.1.14 GetPrototypeFromConstructor
     21 
     22    [...]
     23    3. Let proto be ? Get(constructor, "prototype").
     24    4. If Type(proto) is not Object, then
     25       a. Let realm be ? GetFunctionRealm(constructor).
     26       b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
     27    [...]
     28 features: [generators, cross-realm, Reflect]
     29 ---*/
     30 
     31 var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
     32 var other = $262.createRealm().global;
     33 var OtherGeneratorFunction = Object.getPrototypeOf(
     34  other.eval('(0, function* () {})')
     35 ).constructor;
     36 var C = new other.Function();
     37 C.prototype = null;
     38 
     39 var o = Reflect.construct(GeneratorFunction, [], C);
     40 
     41 assert.sameValue(Object.getPrototypeOf(o), OtherGeneratorFunction.prototype);
     42 
     43 reportCompare(0, 0);