mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1366032. Align IDL record to C++ conversion with the spec when Symbol-named properties are involved. r=qdot
This commit is contained in:
parent
8c95631f40
commit
7c6c40e506
@ -4940,10 +4940,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
|
||||
JS::Rooted<JSObject*> recordObj(cx, &$${val}.toObject());
|
||||
JS::AutoIdVector ids(cx);
|
||||
// Keep skipping symbols until
|
||||
// https://github.com/heycam/webidl/issues/294 is sorted out.
|
||||
if (!js::GetPropertyKeys(cx, recordObj,
|
||||
JSITER_OWNONLY | JSITER_HIDDEN, &ids)) {
|
||||
JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
|
||||
$*{exceptionCode}
|
||||
}
|
||||
if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
|
||||
@ -4963,8 +4961,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
for (size_t i = 0; i < ids.length(); ++i) {
|
||||
curId = ids[i];
|
||||
|
||||
MOZ_ASSERT(!JSID_IS_SYMBOL(curId), "No symbols, we said!");
|
||||
|
||||
JS::Rooted<JS::PropertyDescriptor> desc(cx);
|
||||
if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
|
||||
&desc)) {
|
||||
@ -4978,6 +4974,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
|
||||
idVal = js::IdToValue(curId);
|
||||
${keyType} propName;
|
||||
// This will just throw if idVal is a Symbol, like the spec says
|
||||
// to do.
|
||||
if (!${keyConversionFunction}(cx, idVal, propName)) {
|
||||
$*{exceptionCode}
|
||||
}
|
||||
|
@ -306,6 +306,93 @@ test(function() {
|
||||
assert_equals(h.get("c"), "2");
|
||||
}, "Correct operation ordering with repeated keys");
|
||||
|
||||
// Need to add symbol tests, but those are pending
|
||||
// https://github.com/heycam/webidl/issues/294 being resolved.
|
||||
test(function() {
|
||||
this.add_cleanup(clearLog);
|
||||
var record = {
|
||||
a: "b",
|
||||
[Symbol.toStringTag]: {
|
||||
// Make sure the ToString conversion of the value happens
|
||||
// after the ToString conversion of the key.
|
||||
toString: function () { addLogEntry("toString", [this]); return "nope"; }
|
||||
},
|
||||
c: "d" };
|
||||
var proxy = new Proxy(record, loggingHandler);
|
||||
assert_throws(new TypeError(),
|
||||
function() { var h = new Headers(proxy); });
|
||||
|
||||
assert_equals(log.length, 7);
|
||||
// The first thing is the [[Get]] of Symbol.iterator to figure out whether
|
||||
// we're a sequence, during overload resolution.
|
||||
assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
|
||||
// Then we have the [[OwnPropertyKeys]] from
|
||||
// https://heycam.github.io/webidl/#es-to-record step 4.
|
||||
assert_array_equals(log[1], ["ownKeys", record]);
|
||||
// Then the [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
|
||||
// Then the [[Get]] from step 5.2.
|
||||
assert_array_equals(log[3], ["get", record, "a", proxy]);
|
||||
// Then the second [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[4], ["getOwnPropertyDescriptor", record, "c"]);
|
||||
// Then the second [[Get]] from step 5.2.
|
||||
assert_array_equals(log[5], ["get", record, "c", proxy]);
|
||||
// Then the third [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[6], ["getOwnPropertyDescriptor", record,
|
||||
Symbol.toStringTag]);
|
||||
// Then we throw an exception converting the Symbol to a string, before we do
|
||||
// the third [[Get]].
|
||||
}, "Basic operation with Symbol keys");
|
||||
|
||||
test(function() {
|
||||
this.add_cleanup(clearLog);
|
||||
var record = {
|
||||
a: {
|
||||
toString: function() { addLogEntry("toString", [this]); return "b"; }
|
||||
},
|
||||
[Symbol.toStringTag]: {
|
||||
toString: function () { addLogEntry("toString", [this]); return "nope"; }
|
||||
},
|
||||
c: {
|
||||
toString: function() { addLogEntry("toString", [this]); return "d"; }
|
||||
}
|
||||
};
|
||||
// Now make that Symbol-named property not enumerable.
|
||||
Object.defineProperty(record, Symbol.toStringTag, { enumerable: false });
|
||||
assert_array_equals(Reflect.ownKeys(record),
|
||||
["a", "c", Symbol.toStringTag]);
|
||||
|
||||
var proxy = new Proxy(record, loggingHandler);
|
||||
var h = new Headers(proxy);
|
||||
|
||||
assert_equals(log.length, 9);
|
||||
// The first thing is the [[Get]] of Symbol.iterator to figure out whether
|
||||
// we're a sequence, during overload resolution.
|
||||
assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
|
||||
// Then we have the [[OwnPropertyKeys]] from
|
||||
// https://heycam.github.io/webidl/#es-to-record step 4.
|
||||
assert_array_equals(log[1], ["ownKeys", record]);
|
||||
// Then the [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
|
||||
// Then the [[Get]] from step 5.2.
|
||||
assert_array_equals(log[3], ["get", record, "a", proxy]);
|
||||
// Then the ToString on the value.
|
||||
assert_array_equals(log[4], ["toString", record.a]);
|
||||
// Then the second [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[5], ["getOwnPropertyDescriptor", record, "c"]);
|
||||
// Then the second [[Get]] from step 5.2.
|
||||
assert_array_equals(log[6], ["get", record, "c", proxy]);
|
||||
// Then the ToString on the value.
|
||||
assert_array_equals(log[7], ["toString", record.c]);
|
||||
// Then the third [[GetOwnProperty]] from step 5.1.
|
||||
assert_array_equals(log[8], ["getOwnPropertyDescriptor", record,
|
||||
Symbol.toStringTag]);
|
||||
// No [[Get]] because not enumerable.
|
||||
|
||||
// Check the results.
|
||||
assert_equals([...h].length, 2);
|
||||
assert_array_equals([...h.keys()], ["a", "c"]);
|
||||
assert_true(h.has("a"));
|
||||
assert_equals(h.get("a"), "b");
|
||||
assert_true(h.has("c"));
|
||||
assert_equals(h.get("c"), "d");
|
||||
}, "Operation with non-enumerable Symbol keys");
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user