From 510b8a85e9a655fa735ef2ca69e5eedef33f3b98 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 13 Mar 2013 14:48:59 -0700 Subject: [PATCH] Bug 849730 - Let objectClassIs through for COWs. r=mrbkap --- js/xpconnect/tests/unit/test_bug849730.js | 7 +++++++ js/xpconnect/tests/unit/xpcshell.ini | 1 + js/xpconnect/wrappers/ChromeObjectWrapper.cpp | 10 ++++++++++ js/xpconnect/wrappers/ChromeObjectWrapper.h | 3 +++ 4 files changed, 21 insertions(+) create mode 100644 js/xpconnect/tests/unit/test_bug849730.js diff --git a/js/xpconnect/tests/unit/test_bug849730.js b/js/xpconnect/tests/unit/test_bug849730.js new file mode 100644 index 000000000000..9fccdc6956bc --- /dev/null +++ b/js/xpconnect/tests/unit/test_bug849730.js @@ -0,0 +1,7 @@ +const Cu = Components.utils; + +function run_test() { + var sb = new Cu.Sandbox('http://www.example.com'); + sb.arr = [3, 4]; + do_check_true(Cu.evalInSandbox('Array.isArray(arr);', sb)); +} diff --git a/js/xpconnect/tests/unit/xpcshell.ini b/js/xpconnect/tests/unit/xpcshell.ini index 9be45117a9a9..40b037cd36c0 100644 --- a/js/xpconnect/tests/unit/xpcshell.ini +++ b/js/xpconnect/tests/unit/xpcshell.ini @@ -16,6 +16,7 @@ tail = [test_bug805807.js] [test_bug809652.js] [test_bug845201.js] +[test_bug849730.js] [test_bug_442086.js] [test_file.js] [test_blob.js] diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp index 68a84d0dc703..7caf610772b7 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp @@ -147,6 +147,16 @@ ChromeObjectWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, return js::GetGeneric(cx, wrapperProto, receiver, id, vp); } +// SecurityWrapper categorically returns false for objectClassIs, but the +// contacts API depends on Array.isArray returning true for COW-implemented +// contacts. This isn't really ideal, but make it work for now. +bool +ChromeObjectWrapper::objectClassIs(JSObject *obj, js::ESClassValue classValue, + JSContext *cx) +{ + return CrossCompartmentWrapper::objectClassIs(obj, classValue, cx); +} + // This mechanism isn't ideal because we end up calling enter() on the base class // twice (once during enter() here and once during the trap itself), and policy // enforcement or COWs isn't cheap. But it results in the cleanest code, and this diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.h b/js/xpconnect/wrappers/ChromeObjectWrapper.h index 1a98f3a9026f..4dbafcb29437 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.h +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.h @@ -37,6 +37,9 @@ class ChromeObjectWrapper : public ChromeObjectWrapperBase virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, js::Value *vp) MOZ_OVERRIDE; + virtual bool objectClassIs(JSObject *obj, js::ESClassValue classValue, + JSContext *cx) MOZ_OVERRIDE; + virtual bool enter(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act, bool *bp) MOZ_OVERRIDE;