Bug 939696 - isProxy for Cu. r=bholley
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Tue, 26 Nov 2013 14:54:02 +0100
changeset 157532 017167e2056a
parent 157531 27327f3e2943
child 157533 6728f7b4e467
push id25716
push userkwierso@gmail.com
push date2013-11-27 01:32 +0000
treeherdermozilla-central@d822990ba9ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs939696
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 939696 - isProxy for Cu. r=bholley
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -115,17 +115,17 @@ interface nsIXPCComponents_utils_Sandbox
 interface ScheduledGCCallback : nsISupports
 {
     void callback();
 };
 
 /**
 * interface of Components.utils
 */
-[scriptable, uuid(12368474-b448-4ac6-ba2c-db1966a7a697)]
+[scriptable, uuid(ef621cac-c818-464a-9fb1-9a35731a7f32)]
 interface nsIXPCComponents_Utils : nsISupports
 {
 
     /* reportError is designed to be called from JavaScript only.
      *
      * It will report a JS Error object to the JS console, and return. It
      * is meant for use in exception handler blocks which want to "eat"
      * an exception, but still want to report it to the console.
@@ -303,16 +303,25 @@ interface nsIXPCComponents_Utils : nsISu
      *
      * @param obj The JavaScript object whose global is to be gotten.
      * @return the corresponding global.
      */
     [implicit_jscontext]
     jsval getGlobalForObject(in jsval obj);
 
     /*
+     * To be called from JS only.
+     *
+     * Returns the true if the object is a (scripted) proxy.
+     * NOTE: Security wrappers are unwrapped first before the check.
+     */
+    [implicit_jscontext]
+    boolean isProxy(in jsval vobject);
+
+    /*
      * Similar to evalInSandbox except this one is used to eval a script in the
      * scope of a window. Also note, that the return value and the possible exceptions
      * in the script are structured cloned, unless they are natives (then they are just
      * wrapped).
      * Principal of the caller must subsume the target's.
      */
     [implicit_jscontext]
     jsval evalInWindow(in AString source, in jsval window);
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3052,16 +3052,33 @@ xpc::CreateObjectIn(JSContext *cx, Handl
 
     rval.setObject(*obj);
     if (!WrapperFactory::WaiveXrayAndWrap(cx, rval))
         return false;
 
     return true;
 }
 
+/* boolean isProxy(in value vobj); */
+NS_IMETHODIMP
+nsXPCComponents_Utils::IsProxy(const Value &vobj, JSContext *cx, bool *rval)
+{
+    if (!vobj.isObject()) {
+        *rval = false;
+        return NS_OK;
+    }
+
+    RootedObject obj(cx, &vobj.toObject());
+    obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
+    NS_ENSURE_TRUE(obj, NS_ERROR_FAILURE);
+
+    *rval = js::IsScriptedProxy(obj);
+    return NS_OK;
+}
+
 /* jsval evalInWindow(in string source, in jsval window); */
 NS_IMETHODIMP
 nsXPCComponents_Utils::EvalInWindow(const nsAString &source, const Value &window,
                                     JSContext *cx, Value *rval)
 {
     if (!window.isObject())
         return NS_ERROR_INVALID_ARG;