mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-12 10:40:12 +00:00
Added Option constructor and nsIJSNativeIntializer.h interface. DOM glue code now uses the nsIJSNativeIntializer interface to initialize newly constructed instances.
This commit is contained in:
parent
84919aed9a
commit
18d2335318
@ -28,6 +28,7 @@
|
||||
#include "nsIDOMNamedNodeMap.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIDOMHTMLOptionElement.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIScriptNameSetRegistry.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
@ -243,8 +244,9 @@ nsJSContext::InitClasses()
|
||||
NS_OK == NS_InitNodeListClass(this, nsnull) &&
|
||||
NS_OK == InitializeExternalClasses() &&
|
||||
NS_OK == InitializeLiveConnectClasses() &&
|
||||
// XXX Temporarily here. This shouldn't be hardcoded.
|
||||
NS_OK == NS_InitHTMLImageElementClass(this, nsnull)) {
|
||||
// XXX Temporarily here. These shouldn't be hardcoded.
|
||||
NS_OK == NS_InitHTMLImageElementClass(this, nsnull) &&
|
||||
NS_OK == NS_InitHTMLOptionElementClass(this, nsnull)) {
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "nsIDOMPluginArray.h"
|
||||
#include "nsIDOMMimeTypeArray.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "nsDOMCID.h"
|
||||
|
||||
|
||||
@ -469,8 +470,10 @@ HTMLImageElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
||||
nsIScriptNameSpaceManager* manager;
|
||||
nsIDOMHTMLImageElement *nativeThis;
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
nsIJSNativeInitializer* initializer = nsnull;
|
||||
|
||||
static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIJSNativeInitializerIID, NS_IJSNATIVEINITIALIZER_IID);
|
||||
|
||||
result = context->GetNameSpaceManager(&manager);
|
||||
if (NS_OK != result) {
|
||||
@ -491,7 +494,19 @@ HTMLImageElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// XXX We should be calling Init() on the instance
|
||||
result = nativeThis->QueryInterface(kIJSNativeInitializerIID, (void **)&initializer);
|
||||
if (NS_OK != result) {
|
||||
NS_RELEASE(nativeThis);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = initializer->Initialize(cx, argc, argv);
|
||||
NS_RELEASE(initializer);
|
||||
|
||||
if (NS_OK != result) {
|
||||
NS_RELEASE(nativeThis);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
|
||||
if (NS_OK != result) {
|
||||
|
@ -28,6 +28,11 @@
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMHTMLFormElement.h"
|
||||
#include "nsIDOMHTMLOptionElement.h"
|
||||
#include "nsIDOMOption.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "nsDOMCID.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
@ -35,9 +40,11 @@ static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIOptionIID, NS_IDOMOPTION_IID);
|
||||
|
||||
NS_DEF_PTR(nsIDOMHTMLFormElement);
|
||||
NS_DEF_PTR(nsIDOMHTMLOptionElement);
|
||||
NS_DEF_PTR(nsIDOMOption);
|
||||
|
||||
//
|
||||
// HTMLOptionElement property ids
|
||||
@ -333,9 +340,62 @@ static JSFunctionSpec HTMLOptionElementMethods[] =
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
HTMLOptionElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsresult result;
|
||||
nsIID classID;
|
||||
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
|
||||
nsIScriptNameSpaceManager* manager;
|
||||
nsIDOMHTMLOptionElement *nativeThis;
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
nsIJSNativeInitializer* initializer = nsnull;
|
||||
|
||||
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIJSNativeInitializerIID, NS_IJSNATIVEINITIALIZER_IID);
|
||||
|
||||
result = context->GetNameSpaceManager(&manager);
|
||||
if (NS_OK != result) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = manager->LookupName("HTMLOptionElement", PR_TRUE, classID);
|
||||
NS_RELEASE(manager);
|
||||
if (NS_OK != result) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = nsComponentManager::CreateInstance(classID,
|
||||
nsnull,
|
||||
kIDOMHTMLOptionElementIID,
|
||||
(void **)&nativeThis);
|
||||
if (NS_OK != result) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = nativeThis->QueryInterface(kIJSNativeInitializerIID, (void **)&initializer);
|
||||
if (NS_OK != result) {
|
||||
NS_RELEASE(nativeThis);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = initializer->Initialize(cx, argc, argv);
|
||||
NS_RELEASE(initializer);
|
||||
|
||||
if (NS_OK != result) {
|
||||
NS_RELEASE(nativeThis);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
|
||||
if (NS_OK != result) {
|
||||
NS_RELEASE(nativeThis);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
owner->SetScriptObject((void *)obj);
|
||||
JS_SetPrivate(cx, obj, nativeThis);
|
||||
|
||||
NS_RELEASE(owner);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// HTMLOptionElement class initialization
|
||||
@ -372,6 +432,7 @@ extern "C" NS_DOM nsresult NS_InitHTMLOptionElementClass(nsIScriptContext *aCont
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS_AliasProperty(jscontext, global, "HTMLOptionElement", "Option");
|
||||
}
|
||||
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
|
||||
proto = JSVAL_TO_OBJECT(vp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user