tor-browser

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

subclassing.js (1508B)


      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-date-value
      5 description: Error retrieving `Symbol.toPrimitive` method from object value
      6 info: |
      7  3. If NewTarget is not undefined, then
      8     [...]
      9     c. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DatePrototype%",
     10        « [[DateValue]] »).
     11     [...]
     12 
     13  OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ ,
     14  internalSlotsList ] )
     15 
     16  [...]
     17  2. Let proto be ? GetPrototypeFromConstructor(constructor,
     18     intrinsicDefaultProto).
     19  3. Return ObjectCreate(proto, internalSlotsList).
     20 features: [Reflect]
     21 ---*/
     22 
     23 var callCount = 0;
     24 var Ctor = function() {
     25  callCount += 1;
     26 };
     27 var instance;
     28 
     29 instance = Reflect.construct(Date, [64], Ctor);
     30 
     31 assert.sameValue(
     32  Object.getPrototypeOf(instance),
     33  Ctor.prototype,
     34  'constructor defines an object `prototype` property'
     35 );
     36 assert.sameValue(callCount, 0, 'constructor not invoked');
     37 assert.sameValue(
     38  Date.prototype.getTime.call(instance),
     39  64,
     40  'proper subclass has a [[DateValue]] slot'
     41 );
     42 
     43 Ctor.prototype = null;
     44 instance = Reflect.construct(Date, [64], Ctor);
     45 
     46 assert.sameValue(
     47  Object.getPrototypeOf(instance),
     48  Date.prototype,
     49  'constructor does not defines an object `prototype` property'
     50 );
     51 assert.sameValue(callCount, 0, 'constructor not invoked');
     52 assert.sameValue(
     53  instance.getTime(), 64, 'direct instance has a [[DateValue]] slot'
     54 );
     55 
     56 reportCompare(0, 0);