2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
1998-12-03 00:33:00 +00:00
|
|
|
|
1998-12-22 22:03:20 +00:00
|
|
|
#ifndef nsJSUtils_h__
|
|
|
|
#define nsJSUtils_h__
|
|
|
|
|
1998-12-03 00:33:00 +00:00
|
|
|
/**
|
|
|
|
* This is not a generated file. It contains common utility functions
|
|
|
|
* invoked from the JavaScript code generated from IDL interfaces.
|
|
|
|
* The goal of the utility functions is to cut down on the size of
|
|
|
|
* the generated code itself.
|
|
|
|
*/
|
|
|
|
|
2012-06-02 06:39:06 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
|
1998-12-03 00:33:00 +00:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-03-28 22:19:42 +00:00
|
|
|
class nsIDOMEventListener;
|
1999-12-18 20:29:29 +00:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsIScriptGlobalObject;
|
2008-03-06 22:52:58 +00:00
|
|
|
class nsIPrincipal;
|
1999-03-28 22:19:42 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
class nsJSUtils
|
|
|
|
{
|
1998-12-22 22:03:20 +00:00
|
|
|
public:
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t* aLineno);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2012-11-09 15:43:57 +00:00
|
|
|
static nsIScriptGlobalObject *GetStaticScriptGlobal(JSObject* aObj);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2012-11-09 15:43:57 +00:00
|
|
|
static nsIScriptContext *GetStaticScriptContext(JSObject* aObj);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext);
|
2010-12-20 16:21:58 +00:00
|
|
|
|
|
|
|
/**
|
2011-08-24 20:44:35 +00:00
|
|
|
* Retrieve the inner window ID based on the given JSContext.
|
2010-12-20 16:21:58 +00:00
|
|
|
*
|
|
|
|
* @param JSContext aContext
|
2011-08-24 20:44:35 +00:00
|
|
|
* The JSContext from which you want to find the inner window ID.
|
2010-12-20 16:21:58 +00:00
|
|
|
*
|
2012-08-22 15:56:38 +00:00
|
|
|
* @returns uint64_t the inner window ID.
|
2010-12-20 16:21:58 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint64_t GetCurrentlyRunningCodeInnerWindowID(JSContext *aContext);
|
2012-11-09 15:43:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Report a pending exception on aContext, if any. Note that this
|
|
|
|
* can be called when the context has a JS stack. If that's the
|
|
|
|
* case, the stack will be set aside before reporting the exception.
|
|
|
|
*/
|
|
|
|
static void ReportPendingException(JSContext *aContext);
|
2004-02-09 22:48:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class nsDependentJSString : public nsDependentString
|
|
|
|
{
|
|
|
|
public:
|
2010-12-03 08:24:17 +00:00
|
|
|
/**
|
|
|
|
* In the case of string ids, getting the string's chars is infallible, so
|
|
|
|
* the dependent string can be constructed directly.
|
|
|
|
*/
|
|
|
|
explicit nsDependentJSString(jsid id)
|
|
|
|
: nsDependentString(JS_GetInternedStringChars(JSID_TO_STRING(id)),
|
|
|
|
JS_GetStringLength(JSID_TO_STRING(id)))
|
2004-02-09 22:48:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-02 06:39:06 +00:00
|
|
|
/**
|
|
|
|
* Ditto for flat strings.
|
|
|
|
*/
|
|
|
|
explicit nsDependentJSString(JSFlatString* fstr)
|
|
|
|
: nsDependentString(JS_GetFlatStringChars(fstr),
|
|
|
|
JS_GetStringLength(JS_FORGET_STRING_FLATNESS(fstr)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
/**
|
|
|
|
* For all other strings, the nsDependentJSString object should be default
|
|
|
|
* constructed, which leaves it empty (this->IsEmpty()), and initialized with
|
2012-06-02 06:39:06 +00:00
|
|
|
* one of the init() methods below.
|
2010-12-03 08:24:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
nsDependentJSString()
|
2010-07-15 06:19:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
JSBool init(JSContext* aContext, JSString* str)
|
2010-07-15 06:19:36 +00:00
|
|
|
{
|
2010-12-03 08:24:17 +00:00
|
|
|
size_t length;
|
|
|
|
const jschar* chars = JS_GetStringCharsZAndLength(aContext, str, &length);
|
|
|
|
if (!chars)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
NS_ASSERTION(IsEmpty(), "init() on initialized string");
|
|
|
|
nsDependentString* base = this;
|
|
|
|
new(base) nsDependentString(chars, length);
|
|
|
|
return JS_TRUE;
|
2010-07-15 06:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
JSBool init(JSContext* aContext, const jsval &v)
|
2004-02-09 22:48:53 +00:00
|
|
|
{
|
2010-12-03 08:24:17 +00:00
|
|
|
return init(aContext, JSVAL_TO_STRING(v));
|
2004-02-09 22:48:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 06:39:06 +00:00
|
|
|
void init(JSFlatString* fstr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsEmpty(), "init() on initialized string");
|
|
|
|
new(this) nsDependentJSString(fstr);
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
~nsDependentJSString()
|
|
|
|
{
|
|
|
|
}
|
1998-12-22 22:03:20 +00:00
|
|
|
};
|
1998-12-03 00:33:00 +00:00
|
|
|
|
1998-12-22 22:03:20 +00:00
|
|
|
#endif /* nsJSUtils_h__ */
|