dom/base/nsDOMJSUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/nsDOMJSUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsDOMJSUtils_h__
     1.9 +#define nsDOMJSUtils_h__
    1.10 +
    1.11 +#include "nsIScriptContext.h"
    1.12 +#include "jsapi.h"
    1.13 +
    1.14 +class nsIJSArgArray;
    1.15 +
    1.16 +// seems like overkill for just this 1 function - but let's see what else
    1.17 +// falls out first.
    1.18 +inline nsIScriptContext *
    1.19 +GetScriptContextFromJSContext(JSContext *cx)
    1.20 +{
    1.21 +  if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
    1.22 +    return nullptr;
    1.23 +  }
    1.24 +
    1.25 +  nsCOMPtr<nsIScriptContext> scx =
    1.26 +    do_QueryInterface(static_cast<nsISupports *>
    1.27 +                                 (::JS_GetContextPrivate(cx)));
    1.28 +
    1.29 +  // This will return a pointer to something that's about to be
    1.30 +  // released, but that's ok here.
    1.31 +  return scx;
    1.32 +}
    1.33 +
    1.34 +JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
    1.35 +
    1.36 +// A factory function for turning a JS::Value argv into an nsIArray
    1.37 +// but also supports an effecient way of extracting the original argv.
    1.38 +// Bug 312003 describes why this must be "void *", but argv will be cast to
    1.39 +// JS::Value* and the args are found at:
    1.40 +//    ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1]
    1.41 +// The resulting object will take a copy of the array, and ensure each
    1.42 +// element is rooted.
    1.43 +// Optionally, aArgv may be nullptr, in which case the array is allocated and
    1.44 +// rooted, but all items remain nullptr.  This presumably means the caller
    1.45 +// will then QI us for nsIJSArgArray, and set our array elements.
    1.46 +nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv,
    1.47 +                         nsIJSArgArray **aArray);
    1.48 +
    1.49 +#endif // nsDOMJSUtils_h__

mercurial