Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Date/value-to-primitive-get-meth-err.js

raw
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 es6id: 20.3.2.2
6 description: Error retrieving `Symbol.toPrimitive` method from object value
7 info: |
8 3. If NewTarget is not undefined, then
9 a. If Type(value) is Object and value has a [[DateValue]] internal slot, then
10 i. Let tv be thisTimeValue(value).
11 b. Else,
12 i. Let v be ? ToPrimitive(value).
13 [...]
14 features: [Symbol.toPrimitive]
15 ---*/
16
17 var poisonedObject = {};
18 var poisonedDate = new Date();
19 Object.defineProperty(poisonedObject, Symbol.toPrimitive, {
20 get: function() {
21 throw new Test262Error();
22 }
23 });
24 Object.defineProperty(poisonedDate, Symbol.toPrimitive, {
25 get: function() {
26 throw new Test262Error();
27 }
28 });
29
30 Date(poisonedObject);
31
32 new Date(poisonedDate);
33
34 assert.throws(Test262Error, function() {
35 new Date(poisonedObject);
36 });