mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 03:49:42 +00:00
Fix for bug 27775. Introduced idl keyword 'replaceable' and marked some of the newer window properties with it. Fixes pages like www.oracle.com that have define window-scoped variables with the same name. r=rginda, a=chofmann
This commit is contained in:
parent
6ad008c507
commit
e5b64e43ae
@ -9,8 +9,8 @@
|
||||
readonly attribute History history;
|
||||
readonly attribute Window parent;
|
||||
readonly attribute Window top;
|
||||
readonly attribute Window content;
|
||||
readonly attribute xpidl nsISidebar sidebar;
|
||||
readonly replaceable attribute Window content;
|
||||
readonly replaceable attribute xpidl nsISidebar sidebar;
|
||||
readonly attribute BarProp menubar;
|
||||
readonly attribute BarProp toolbar;
|
||||
readonly attribute BarProp locationbar;
|
||||
@ -20,7 +20,7 @@
|
||||
readonly attribute BarProp directories;
|
||||
readonly attribute boolean closed;
|
||||
readonly attribute WindowCollection frames;
|
||||
readonly attribute xpidl nsIControllers controllers;
|
||||
readonly replaceable attribute xpidl nsIControllers controllers;
|
||||
attribute Window opener;
|
||||
attribute wstring status;
|
||||
attribute wstring defaultStatus;
|
||||
|
@ -272,42 +272,6 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_CONTENT:
|
||||
{
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTENT, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
nsIDOMWindow* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetContent(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object
|
||||
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_SIDEBAR:
|
||||
{
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_SIDEBAR, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
nsISidebar* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetSidebar(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, NS_GET_IID(nsISidebar), cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_MENUBAR:
|
||||
{
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_MENUBAR, PR_FALSE);
|
||||
@ -469,24 +433,6 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_CONTROLLERS:
|
||||
{
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTROLLERS, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
nsIControllers* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetControllers(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, NS_GET_IID(nsIControllers), cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_OPENER:
|
||||
{
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_OPENER, PR_FALSE);
|
||||
@ -978,6 +924,219 @@ SetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// content Property Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowcontentGetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTENT, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
nsIDOMWindow* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetContent(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object
|
||||
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// content Property Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowcontentSetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTENT, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
|
||||
JS_DefineProperty(cx, obj, "content", *vp, nsnull, nsnull, JSPROP_ENUMERATE);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// sidebar Property Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowsidebarGetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_SIDEBAR, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
nsISidebar* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetSidebar(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, NS_GET_IID(nsISidebar), cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// sidebar Property Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowsidebarSetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_SIDEBAR, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
|
||||
JS_DefineProperty(cx, obj, "sidebar", *vp, nsnull, nsnull, JSPROP_ENUMERATE);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// controllers Property Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowcontrollersGetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTROLLERS, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
nsIControllers* prop;
|
||||
nsresult result = NS_OK;
|
||||
result = a->GetControllers(&prop);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, NS_GET_IID(nsIControllers), cx, obj, vp);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// controllers Property Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowcontrollersSetter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMWindow *a = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
|
||||
}
|
||||
|
||||
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_CONTROLLERS, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, rv);
|
||||
}
|
||||
|
||||
|
||||
JS_DefineProperty(cx, obj, "controllers", *vp, nsnull, nsnull, JSPROP_ENUMERATE);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Window finalizer
|
||||
@ -2800,8 +2959,8 @@ static JSPropertySpec WindowProperties[] =
|
||||
{"history", WINDOW_HISTORY, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"parent", WINDOW_PARENT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"top", WINDOW_TOP, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"content", WINDOW_CONTENT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"sidebar", WINDOW_SIDEBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"content", WINDOW_CONTENT, JSPROP_ENUMERATE, WindowcontentGetter, WindowcontentSetter},
|
||||
{"sidebar", WINDOW_SIDEBAR, JSPROP_ENUMERATE, WindowsidebarGetter, WindowsidebarSetter},
|
||||
{"menubar", WINDOW_MENUBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"toolbar", WINDOW_TOOLBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"locationbar", WINDOW_LOCATIONBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
@ -2811,7 +2970,7 @@ static JSPropertySpec WindowProperties[] =
|
||||
{"directories", WINDOW_DIRECTORIES, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"closed", WINDOW_CLOSED, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"frames", WINDOW_FRAMES, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"controllers", WINDOW_CONTROLLERS, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"controllers", WINDOW_CONTROLLERS, JSPROP_ENUMERATE, WindowcontrollersGetter, WindowcontrollersSetter},
|
||||
{"opener", WINDOW_OPENER, JSPROP_ENUMERATE},
|
||||
{"status", WINDOW_STATUS, JSPROP_ENUMERATE},
|
||||
{"defaultStatus", WINDOW_DEFAULTSTATUS, JSPROP_ENUMERATE},
|
||||
|
@ -39,6 +39,7 @@ IdlAttribute::IdlAttribute()
|
||||
{
|
||||
mReadOnly = 0;
|
||||
mIsNoScript = 0;
|
||||
mReplaceable = 0;
|
||||
}
|
||||
|
||||
IdlAttribute::~IdlAttribute()
|
||||
@ -66,3 +67,15 @@ IdlAttribute::SetIsNoScript(int aIsNoScript)
|
||||
{
|
||||
mIsNoScript = aIsNoScript;
|
||||
}
|
||||
|
||||
int
|
||||
IdlAttribute::GetReplaceable()
|
||||
{
|
||||
return mReplaceable;
|
||||
}
|
||||
|
||||
void
|
||||
IdlAttribute::SetReplaceable(int aReplaceable)
|
||||
{
|
||||
mReplaceable = aReplaceable;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class IdlAttribute : public IdlVariable {
|
||||
private:
|
||||
int mReadOnly;
|
||||
int mIsNoScript;
|
||||
int mReplaceable;
|
||||
|
||||
public:
|
||||
IdlAttribute();
|
||||
@ -40,6 +41,9 @@ public:
|
||||
|
||||
int GetIsNoScript();
|
||||
void SetIsNoScript(int aIsNoScript);
|
||||
|
||||
int GetReplaceable();
|
||||
void SetReplaceable(int aReplaceable);
|
||||
};
|
||||
|
||||
#ifdef XP_MAC
|
||||
|
@ -309,6 +309,7 @@ void IdlParser::ParseInterfaceBody(IdlSpecification &aSpecification, IdlInterfac
|
||||
break;
|
||||
case READONLY_TOKEN:
|
||||
case ATTRIBUTE_TOKEN:
|
||||
case REPLACEABLE_TOKEN:
|
||||
aInterface.AddAttribute(ParseAttribute(aSpecification, token->id));
|
||||
break;
|
||||
default:
|
||||
@ -561,7 +562,7 @@ IdlAttribute* IdlParser::MaybeParseAttribute(IdlSpecification &aSpecification, i
|
||||
isNoScript = 1;
|
||||
TrimComments();
|
||||
token = mScanner->PeekToken();
|
||||
if ((token->id != READONLY_TOKEN) && (token->id != ATTRIBUTE_TOKEN)) {
|
||||
if ((token->id != READONLY_TOKEN) && (token->id != ATTRIBUTE_TOKEN) && (token->id != REPLACEABLE_TOKEN)) {
|
||||
return NULL;
|
||||
}
|
||||
mScanner->NextToken();
|
||||
@ -572,23 +573,32 @@ IdlAttribute* IdlParser::MaybeParseAttribute(IdlSpecification &aSpecification, i
|
||||
}
|
||||
|
||||
/**
|
||||
* attr_dcl = [ "readonly" ] "attribute" param_type_spec identifier
|
||||
* attr_dcl = [ "readonly" ] [ "replaceable" ] "attribute" param_type_spec identifier
|
||||
* param_type_spec = base_type_spec / string_type / scoped_name
|
||||
*/
|
||||
IdlAttribute* IdlParser::ParseAttribute(IdlSpecification &aSpecification, int aTokenID, int aIsNoScript)
|
||||
{
|
||||
Token *token;
|
||||
int isReadOnly = 0;
|
||||
int isReplaceable = 0;
|
||||
|
||||
// if it was a readonly keyword read the next keyword
|
||||
if (READONLY_TOKEN == aTokenID) {
|
||||
isReadOnly = 1;
|
||||
TrimComments();
|
||||
token = mScanner->NextToken();
|
||||
aTokenID = token->id;
|
||||
}
|
||||
if (ATTRIBUTE_TOKEN != aTokenID) {
|
||||
throw AttributeParsingException("Missing attribute specifier.");
|
||||
while (aTokenID != ATTRIBUTE_TOKEN) {
|
||||
// if it was a readonly keyword read the next keyword
|
||||
if (READONLY_TOKEN == aTokenID) {
|
||||
isReadOnly = 1;
|
||||
TrimComments();
|
||||
token = mScanner->NextToken();
|
||||
aTokenID = token->id;
|
||||
}
|
||||
else if (REPLACEABLE_TOKEN == aTokenID) {
|
||||
isReplaceable = 1;
|
||||
TrimComments();
|
||||
token = mScanner->NextToken();
|
||||
aTokenID = token->id;
|
||||
}
|
||||
else {
|
||||
throw AttributeParsingException("Unknown attribute specifier.");
|
||||
}
|
||||
}
|
||||
TrimComments();
|
||||
|
||||
@ -596,6 +606,7 @@ IdlAttribute* IdlParser::ParseAttribute(IdlSpecification &aSpecification, int aT
|
||||
IdlAttribute *attrObj = new IdlAttribute();
|
||||
attrObj->SetIsNoScript(aIsNoScript);
|
||||
attrObj->SetReadOnly(isReadOnly);
|
||||
attrObj->SetReplaceable(isReplaceable);
|
||||
|
||||
// this must be the attribute type
|
||||
token = mScanner->NextToken();
|
||||
|
@ -947,6 +947,33 @@ void IdlScanner::RKeywords(char *aCurrentPos, Token *aToken)
|
||||
aToken->SetToken(RAISES_TOKEN);
|
||||
}
|
||||
}
|
||||
else if (c != EOF && c == 'p' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'l' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'a' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'c' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'e' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'a' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'b' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'l' && (*aCurrentPos++ = c) && (c = mInputFile->get()) &&
|
||||
c != EOF && c == 'e' && (*aCurrentPos++ = c)) {
|
||||
// if terminated is a keyword
|
||||
c = mInputFile->get();
|
||||
if (c != EOF) {
|
||||
if (isalpha(c) || isdigit(c) || c == '_') {
|
||||
// more characters, it must be an identifier
|
||||
*aCurrentPos++ = c;
|
||||
Identifier(aCurrentPos, aToken);
|
||||
}
|
||||
else {
|
||||
// it is a keyword
|
||||
aToken->SetToken(REPLACEABLE_TOKEN);
|
||||
mInputFile->putback(c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aToken->SetToken(REPLACEABLE_TOKEN);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// it must be an identifier
|
||||
KeywordMismatch(c, aCurrentPos, aToken);
|
||||
|
@ -79,6 +79,7 @@ enum EIDLTokenType {
|
||||
VOID_TOKEN,
|
||||
NOSCRIPT_TOKEN,
|
||||
UNKNOWN_TOKEN,
|
||||
REPLACEABLE_TOKEN,
|
||||
// constant values
|
||||
INTEGER_CONSTANT = 1000,
|
||||
STRING_CONSTANT
|
||||
|
@ -80,6 +80,7 @@ JSStubGen::Generate(char *aFileName,
|
||||
GeneratePropertySlots(aSpec);
|
||||
GeneratePropertyFunc(aSpec, PR_TRUE);
|
||||
GeneratePropertyFunc(aSpec, PR_FALSE);
|
||||
GenerateCustomPropertyFuncs(aSpec);
|
||||
GenerateFinalize(aSpec);
|
||||
GenerateEnumerate(aSpec);
|
||||
GenerateResolve(aSpec);
|
||||
@ -610,7 +611,7 @@ JSStubGen::GeneratePropertyFunc(IdlSpecification &aSpec, PRBool aIsGetter)
|
||||
strcpy(attr_name, attr->GetName());
|
||||
StrUpr(attr_name);
|
||||
|
||||
if (attr->GetIsNoScript() || (!aIsGetter && (attr->GetReadOnly()))) {
|
||||
if (attr->GetIsNoScript() || attr->GetReplaceable() || (!aIsGetter && (attr->GetReadOnly()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -977,6 +978,98 @@ JSStubGen::GeneratePropSetter(ofstream *file,
|
||||
*file << buf;
|
||||
}
|
||||
|
||||
static const char kCustomPropFuncBeginStr[] = "\n"
|
||||
"/***********************************************************************/\n"
|
||||
"//\n"
|
||||
"// %s Property %ster\n"
|
||||
"//\n"
|
||||
"PR_STATIC_CALLBACK(JSBool)\n"
|
||||
"%s%s%ster(JSContext *cx, JSObject *obj, jsval id, jsval *vp)\n"
|
||||
"{\n"
|
||||
" nsIDOM%s *a = (nsIDOM%s*)nsJSUtils::nsGetNativeThis(cx, obj);\n"
|
||||
"\n"
|
||||
" // If there's no private data, this must be the prototype, so ignore\n"
|
||||
" if (nsnull == a) {\n"
|
||||
" return JS_TRUE;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" nsresult rv;\n"
|
||||
" NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,\n"
|
||||
" NS_SCRIPTSECURITYMANAGER_PROGID, &rv);\n"
|
||||
" if (NS_FAILED(rv)) {\n"
|
||||
" return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_%s_%s, %s);\n"
|
||||
" if (NS_FAILED(rv)) {\n"
|
||||
" return nsJSUtils::nsReportError(cx, obj, rv);\n"
|
||||
" }\n"
|
||||
"\n";
|
||||
|
||||
static const char kCustomPropGetterFuncEndStr[] = "\n"
|
||||
" return PR_TRUE;\n"
|
||||
"}\n";
|
||||
|
||||
static const char kCustomPropSetterFuncEndStr[] = "\n"
|
||||
" JS_DefineProperty(cx, obj, \"%s\", *vp, nsnull, nsnull, JSPROP_ENUMERATE);\n"
|
||||
" return PR_TRUE;\n"
|
||||
"}\n";
|
||||
|
||||
void
|
||||
JSStubGen::GenerateCustomPropertyFuncs(IdlSpecification &aSpec)
|
||||
{
|
||||
char buf[1024];
|
||||
ofstream *file = GetFile();
|
||||
IdlInterface *primary_iface = aSpec.GetInterfaceAt(0);
|
||||
PRBool any = PR_FALSE;
|
||||
static char* get_str = "Get";
|
||||
static char* set_str = "Set";
|
||||
|
||||
int i, icount = aSpec.InterfaceCount();
|
||||
for (i = 0; i < icount; i++) {
|
||||
IdlInterface *iface = aSpec.GetInterfaceAt(i);
|
||||
char iface_name[128];
|
||||
char iface_name_upper[128];
|
||||
|
||||
strcpy(iface_name, iface->GetName());
|
||||
strcpy(iface_name_upper, iface->GetName());
|
||||
StrUpr(iface_name_upper);
|
||||
|
||||
int a, acount = iface->AttributeCount();
|
||||
for (a = 0; a < acount; a++) {
|
||||
IdlAttribute *attr = iface->GetAttributeAt(a);
|
||||
|
||||
if (attr->GetReplaceable()) {
|
||||
char attr_name[128];
|
||||
char attr_name_upper[128];
|
||||
|
||||
strcpy(attr_name, attr->GetName());
|
||||
strcpy(attr_name_upper, attr->GetName());
|
||||
StrUpr(attr_name_upper);
|
||||
|
||||
sprintf(buf, kCustomPropFuncBeginStr, attr_name,
|
||||
get_str, iface_name, attr_name, get_str,
|
||||
iface_name, iface_name, iface_name_upper, attr_name_upper,
|
||||
"PR_FALSE");
|
||||
*file << buf;
|
||||
|
||||
GeneratePropGetter(file, *iface, *attr,
|
||||
iface == primary_iface ? JSSTUBGEN_PRIMARY : JSSTUBGEN_NONPRIMARY);
|
||||
*file << kCustomPropGetterFuncEndStr;
|
||||
|
||||
sprintf(buf, kCustomPropFuncBeginStr, attr_name,
|
||||
set_str, iface_name, attr_name, set_str,
|
||||
iface_name, iface_name, iface_name_upper, attr_name_upper,
|
||||
"PR_TRUE");
|
||||
*file << buf;
|
||||
sprintf(buf, kCustomPropSetterFuncEndStr, attr_name);
|
||||
*file << buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const char kFinalizeStr[] =
|
||||
"\n\n//\n"
|
||||
"// %s finalizer\n"
|
||||
@ -1508,6 +1601,9 @@ static const char kPropSpecEntryStr[] =
|
||||
|
||||
static const char kPropSpecReadOnlyStr[] = " | JSPROP_READONLY";
|
||||
|
||||
static const char kPropSpecEntryReplaceableStr[] =
|
||||
" {\"%s\", %s_%s, JSPROP_ENUMERATE, %s%sGetter, %s%sSetter},\n";
|
||||
|
||||
static const char kPropSpecEndStr[] =
|
||||
" {0}\n"
|
||||
"};\n";
|
||||
@ -1542,9 +1638,16 @@ JSStubGen::GenerateClassProperties(IdlSpecification &aSpec)
|
||||
strcpy(attr_name, attr->GetName());
|
||||
StrUpr(attr_name);
|
||||
|
||||
sprintf(buf, kPropSpecEntryStr, attr->GetName(),
|
||||
iface_name, attr_name,
|
||||
attr->GetReadOnly() ? kPropSpecReadOnlyStr : "");
|
||||
if (attr->GetReplaceable()) {
|
||||
sprintf(buf, kPropSpecEntryReplaceableStr, attr->GetName(),
|
||||
iface_name, attr_name, iface->GetName(), attr->GetName(),
|
||||
iface->GetName(), attr->GetName());
|
||||
}
|
||||
else {
|
||||
sprintf(buf, kPropSpecEntryStr, attr->GetName(),
|
||||
iface_name, attr_name,
|
||||
attr->GetReadOnly() ? kPropSpecReadOnlyStr : "");
|
||||
}
|
||||
*file << buf;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ protected:
|
||||
void GenerateDefPtrs(IdlSpecification &aSpec);
|
||||
void GeneratePropertySlots(IdlSpecification &aSpec);
|
||||
void GeneratePropertyFunc(IdlSpecification &aSpec, PRBool aIsGetter);
|
||||
void GenerateCustomPropertyFuncs(IdlSpecification &aSpec);
|
||||
void GenerateFinalize(IdlSpecification &aSpec);
|
||||
void GenerateEnumerate(IdlSpecification &aSpec);
|
||||
void GenerateResolve(IdlSpecification &aSpec);
|
||||
|
Loading…
x
Reference in New Issue
Block a user