mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1127827, part 2 - Treat missing arguments to weakmap methods as undefined. r=Waldo
Plus add a few tests for various things.
This commit is contained in:
parent
e889f2ba1f
commit
bd07396b02
@ -211,13 +211,7 @@ WeakMap_has_impl(JSContext *cx, CallArgs args)
|
||||
{
|
||||
MOZ_ASSERT(IsWeakMap(args.thisv()));
|
||||
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.has", "0", "s");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args[0].isObject()) {
|
||||
if (!args.get(0).isObject()) {
|
||||
args.rval().setBoolean(false);
|
||||
return true;
|
||||
}
|
||||
@ -267,13 +261,7 @@ WeakMap_get_impl(JSContext *cx, CallArgs args)
|
||||
{
|
||||
MOZ_ASSERT(IsWeakMap(args.thisv()));
|
||||
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.get", "0", "s");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args[0].isObject()) {
|
||||
if (!args.get(0).isObject()) {
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
@ -302,13 +290,7 @@ WeakMap_delete_impl(JSContext *cx, CallArgs args)
|
||||
{
|
||||
MOZ_ASSERT(IsWeakMap(args.thisv()));
|
||||
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.delete", "0", "s");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args[0].isObject()) {
|
||||
if (!args.get(0).isObject()) {
|
||||
args.rval().setBoolean(false);
|
||||
return true;
|
||||
}
|
||||
@ -401,23 +383,16 @@ WeakMap_set_impl(JSContext *cx, CallArgs args)
|
||||
{
|
||||
MOZ_ASSERT(IsWeakMap(args.thisv()));
|
||||
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.set", "0", "s");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args[0].isObject()) {
|
||||
if (!args.get(0).isObject()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT);
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject key(cx, &args[0].toObject());
|
||||
RootedValue value(cx, (args.length() > 1) ? args[1] : UndefinedValue());
|
||||
Rooted<JSObject*> thisObj(cx, &args.thisv().toObject());
|
||||
Rooted<WeakMapObject*> map(cx, &thisObj->as<WeakMapObject>());
|
||||
|
||||
if (!SetWeakMapEntryInternal(cx, map, key, value))
|
||||
if (!SetWeakMapEntryInternal(cx, map, key, args.get(1)))
|
||||
return false;
|
||||
args.rval().set(args.thisv());
|
||||
return true;
|
||||
|
@ -83,7 +83,8 @@ function test()
|
||||
var map = new WeakMap();
|
||||
|
||||
check(function() !map.has(key));
|
||||
map.set(key, 42);
|
||||
check(function() map.delete(key) == false);
|
||||
check(function() map.set(key, 42) === map);
|
||||
check(function() map.get(key) == 42);
|
||||
check(function() typeof map.get({}) == "undefined");
|
||||
check(function() map.get({}, "foo") == "foo");
|
||||
@ -97,14 +98,21 @@ function test()
|
||||
|
||||
check(function() typeof map.get(key) == "undefined");
|
||||
check(function() !map.has(key));
|
||||
check(function() map.delete(key) == false);
|
||||
|
||||
var value = { };
|
||||
map.set(new Object(), value);
|
||||
check(function() map.set(new Object(), value) === map);
|
||||
gc(); gc(); gc();
|
||||
|
||||
check(function() map.has("non-object key") == false);
|
||||
check(function() map.has() == false);
|
||||
check(function() map.get("non-object key") == undefined);
|
||||
check(function() map.get() == undefined);
|
||||
check(function() map.delete("non-object key") == false);
|
||||
check(function() map.delete() == false);
|
||||
|
||||
check(function() map.set(key) === map);
|
||||
check(function() map.get(key) == undefined);
|
||||
|
||||
checkThrows(function() map.set("non-object key", value));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user