Re-write tests for Promise.prototype internal slots

The original implementation of the test for the absense of a
[[PromiseState]] internal slot did not actually assert the documented
semantics. Re-implement the test to rely on the IsPromise abstract
operation (via `Promise.prototype.then`) to accurately ensure that the
object does not have a [[PromiseState]] internal slot.

In relying on the semantics of the `instanceof` operator, the original
test for the [[Prototype]] internal slot was imprecise (the assertion
could be satisfied if additional objects were incorrectly defined on the
prototype chain). Re-write the test to assert the value of the
[[Prototype]] internal slot directly.
This commit is contained in:
Mike Pennisi 2016-06-27 11:00:20 -04:00
parent cc7c77b9a1
commit 1ec40f349a
4 changed files with 42 additions and 29 deletions

View File

@ -1,14 +0,0 @@
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise prototype object is an ordinary object
es6id: S25.4.5_A1.1_T1
author: Sam Mikes
description: Promise prototype does not have [[PromiseState]] internal slot
---*/
assert.throws(TypeError, function() {
Promise.call(Promise.prototype, function () {});
});

View File

@ -1,15 +0,0 @@
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise prototype object is an ordinary object
es6id: S25.4.5_A2.1_T1
author: Sam Mikes
description: Promise prototype is a standard built-in Object
---*/
if (!(Promise.prototype instanceof Object)) {
$ERROR("Expected Promise.prototype to be an Object");
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-promise-prototype-object
es6id: 25.4.5
description: Promise.prototype does not have a [[PromiseState]] internal slot
info: |
The Promise prototype object is the intrinsic object %PromisePrototype%. The
value of the [[Prototype]] internal slot of the Promise prototype object is
the intrinsic object %ObjectPrototype%. The Promise prototype object is an
ordinary object. It does not have a [[PromiseState]] internal slot or any of
the other internal slots of Promise instances.
25.4.5.3 Promise.prototype.then
1. Let promise be the this value.
2. If IsPromise(promise) is false, throw a TypeError exception.
25.4.1.6 IsPromise
1. If Type(x) is not Object, return false.
2. If x does not have a [[PromiseState]] internal slot, return false.
---*/
assert.throws(TypeError, function() {
Promise.prototype.then.call(Promise.prototype, function() {}, function() {});
});

View File

@ -0,0 +1,15 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-promise-prototype-object
es6id: 25.4.5
description: Promise.prototype [[Prototype]] is %ObjectPrototype%
info: |
The Promise prototype object is the intrinsic object %PromisePrototype%. The
value of the [[Prototype]] internal slot of the Promise prototype object is
the intrinsic object %ObjectPrototype%. The Promise prototype object is an
ordinary object. It does not have a [[PromiseState]] internal slot or any of
the other internal slots of Promise instances.
---*/
assert.sameValue(Object.getPrototypeOf(Promise.prototype), Object.prototype);