From 84ddd624f81880cf65d9256dca025ccac7334115 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 24 Dec 2011 09:20:04 +0100 Subject: [PATCH] Bug 712649 - Components.utils.getWeakReference(null) should fail silently; r=bholley --- js/xpconnect/src/XPCJSWeakReference.cpp | 2 +- js/xpconnect/tests/unit/test_js_weak_references.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/xpconnect/src/XPCJSWeakReference.cpp b/js/xpconnect/src/XPCJSWeakReference.cpp index 14be0810f13..2516c07bdec 100644 --- a/js/xpconnect/src/XPCJSWeakReference.cpp +++ b/js/xpconnect/src/XPCJSWeakReference.cpp @@ -49,7 +49,7 @@ nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object) JSAutoRequest ar(cx); if (!object.isObject()) - return NS_ERROR_FAILURE; + return NS_OK; JSObject& obj = object.toObject(); diff --git a/js/xpconnect/tests/unit/test_js_weak_references.js b/js/xpconnect/tests/unit/test_js_weak_references.js index cf2f9408bac..ce8de673eb6 100644 --- a/js/xpconnect/tests/unit/test_js_weak_references.js +++ b/js/xpconnect/tests/unit/test_js_weak_references.js @@ -38,6 +38,14 @@ function run_test() { + // Bug 712649: Calling getWeakReference(null) should work. + try { + var nullWeak = Components.utils.getWeakReference(null); + do_check_true(nullWeak.get() === null); + } catch (e) { + do_check_true(false); + } + var obj = { num: 5, str: 'foo' }; var weak = Components.utils.getWeakReference(obj);