зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1383393 - Also ignore null as Symbol.toPrimitive method. r=jandem
--HG-- extra : rebase_source : c8a11f2152d5f4c1cb7729d521cbceb43f0be37a
This commit is contained in:
Родитель
76448d68d0
Коммит
e73ea68a99
|
@ -3151,7 +3151,7 @@ js::ToPrimitiveSlow(JSContext* cx, JSType preferredType, MutableHandleValue vp)
|
|||
return false;
|
||||
|
||||
// Step 6.
|
||||
if (!method.isUndefined()) {
|
||||
if (!method.isNullOrUndefined()) {
|
||||
// Step 6 of GetMethod. js::Call() below would do this check and throw a
|
||||
// TypeError anyway, but this produces a better error message.
|
||||
if (!IsCallable(method))
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
for (let method of [undefined, null]) {
|
||||
let obj = {
|
||||
[Symbol.toPrimitive]: method,
|
||||
toString: () => "pass",
|
||||
};
|
||||
assertEq("" + obj, "pass");
|
||||
}
|
||||
|
||||
for (let method of [true, false, 0, 123, "", "abc", Symbol(), {}]) {
|
||||
let obj = {
|
||||
[Symbol.toPrimitive]: method,
|
||||
toString: () => "pass",
|
||||
};
|
||||
assertThrowsInstanceOf(() => "" + obj, TypeError);
|
||||
}
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0);
|
Загрузка…
Ссылка в новой задаче