https://github.com/mozilla/gecko-dev
Raw File
Tip revision: 37fd0b11fb1e59ae2d1c0bc5b4e7bf033ff7d11c authored by ffxbld on 05 June 2015, 16:40:03 UTC
Added FIREFOX_38_0_6_RELEASE FIREFOX_38_0_6_BUILD1 tag(s) for changeset 76f8f33b6577. DONTBUILD CLOSED TREE a=release
Tip revision: 37fd0b1
nsDOMJSUtils.h
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsDOMJSUtils_h__
#define nsDOMJSUtils_h__

#include "nsIScriptContext.h"
#include "jsapi.h"

class nsIJSArgArray;

// seems like overkill for just this 1 function - but let's see what else
// falls out first.
inline nsIScriptContext *
GetScriptContextFromJSContext(JSContext *cx)
{
  if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
    return nullptr;
  }

  nsCOMPtr<nsIScriptContext> scx =
    do_QueryInterface(static_cast<nsISupports *>
                                 (::JS_GetContextPrivate(cx)));

  // This will return a pointer to something that's about to be
  // released, but that's ok here.
  return scx;
}

JSObject* GetDefaultScopeFromJSContext(JSContext *cx);

// A factory function for turning a JS::Value argv into an nsIArray
// but also supports an effecient way of extracting the original argv.
// Bug 312003 describes why this must be "void *", but argv will be cast to
// JS::Value* and the args are found at:
//    ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1]
// The resulting object will take a copy of the array, and ensure each
// element is rooted.
// Optionally, aArgv may be nullptr, in which case the array is allocated and
// rooted, but all items remain nullptr.  This presumably means the caller
// will then QI us for nsIJSArgArray, and set our array elements.
nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv,
                         nsIJSArgArray **aArray);

#endif // nsDOMJSUtils_h__
back to top