2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 03:33:00 +03:00
|
|
|
|
1998-12-23 01:03:20 +03:00
|
|
|
#ifndef nsJSUtils_h__
|
|
|
|
#define nsJSUtils_h__
|
|
|
|
|
1998-12-03 03:33:00 +03: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 10:39:06 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
|
1998-12-03 03:33:00 +03:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-03-29 02:19:42 +04:00
|
|
|
class nsIDOMEventListener;
|
1999-12-18 23:29:29 +03:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsIScriptGlobalObject;
|
2008-03-07 01:52:58 +03:00
|
|
|
class nsIPrincipal;
|
1999-03-29 02:19:42 +04:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
class nsJSUtils
|
|
|
|
{
|
1998-12-23 01:03:20 +03: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 21:42:36 +04:00
|
|
|
static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename,
|
2012-08-22 19:56:38 +04: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 21:42:36 +04:00
|
|
|
|
2012-11-09 19:43:57 +04: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 21:42:36 +04:00
|
|
|
|
2012-11-09 19:43:57 +04: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 21:42:36 +04:00
|
|
|
|
2004-02-10 01:48:53 +03: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 21:42:36 +04:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext);
|
2010-12-20 19:21:58 +03:00
|
|
|
|
|
|
|
/**
|
2011-08-25 00:44:35 +04:00
|
|
|
* Retrieve the inner window ID based on the given JSContext.
|
2010-12-20 19:21:58 +03:00
|
|
|
*
|
|
|
|
* @param JSContext aContext
|
2011-08-25 00:44:35 +04:00
|
|
|
* The JSContext from which you want to find the inner window ID.
|
2010-12-20 19:21:58 +03:00
|
|
|
*
|
2012-08-22 19:56:38 +04:00
|
|
|
* @returns uint64_t the inner window ID.
|
2010-12-20 19:21:58 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint64_t GetCurrentlyRunningCodeInnerWindowID(JSContext *aContext);
|
2012-11-09 19:43:57 +04: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-10 01:48:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class nsDependentJSString : public nsDependentString
|
|
|
|
{
|
|
|
|
public:
|
2010-12-03 11:24:17 +03: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-10 01:48:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-02 10:39:06 +04:00
|
|
|
/**
|
|
|
|
* Ditto for flat strings.
|
|
|
|
*/
|
|
|
|
explicit nsDependentJSString(JSFlatString* fstr)
|
|
|
|
: nsDependentString(JS_GetFlatStringChars(fstr),
|
|
|
|
JS_GetStringLength(JS_FORGET_STRING_FLATNESS(fstr)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-03 11:24:17 +03:00
|
|
|
/**
|
|
|
|
* For all other strings, the nsDependentJSString object should be default
|
|
|
|
* constructed, which leaves it empty (this->IsEmpty()), and initialized with
|
2012-06-02 10:39:06 +04:00
|
|
|
* one of the init() methods below.
|
2010-12-03 11:24:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
nsDependentJSString()
|
2010-07-15 10:19:36 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-03 11:24:17 +03:00
|
|
|
JSBool init(JSContext* aContext, JSString* str)
|
2010-07-15 10:19:36 +04:00
|
|
|
{
|
2010-12-03 11:24:17 +03: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 10:19:36 +04:00
|
|
|
}
|
|
|
|
|
2010-12-03 11:24:17 +03:00
|
|
|
JSBool init(JSContext* aContext, const jsval &v)
|
2004-02-10 01:48:53 +03:00
|
|
|
{
|
2010-12-03 11:24:17 +03:00
|
|
|
return init(aContext, JSVAL_TO_STRING(v));
|
2004-02-10 01:48:53 +03:00
|
|
|
}
|
|
|
|
|
2012-06-02 10:39:06 +04:00
|
|
|
void init(JSFlatString* fstr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsEmpty(), "init() on initialized string");
|
|
|
|
new(this) nsDependentJSString(fstr);
|
|
|
|
}
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
~nsDependentJSString()
|
|
|
|
{
|
|
|
|
}
|
1998-12-23 01:03:20 +03:00
|
|
|
};
|
1998-12-03 03:33:00 +03:00
|
|
|
|
1998-12-23 01:03:20 +03:00
|
|
|
#endif /* nsJSUtils_h__ */
|