From 6e53f5662f634e574c6586a0160c60fabb10b138 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 21 Sep 2000 02:42:46 +0000 Subject: [PATCH] Fixing nsbeta3+ 49112. Making with(someimageelement) { src=someurl; } work by dynamically defining the 'src' property in nsHTMLImageElement::Resolve() (since src is defined as [noscript] in the IDL). r/a=vidur, r/a=brendan --- .../html/content/src/nsHTMLImageElement.cpp | 21 +++++++++++++++++++ .../html/content/src/nsHTMLImageElement.cpp | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index 5d5bee4270c6..6df08b6d9a91 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -725,6 +725,27 @@ nsHTMLImageElement::EnumerateProperty(JSContext *aContext, JSObject *aObj) PRBool nsHTMLImageElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID) { + if (JSVAL_IS_STRING(aID) && mInner.mDOMSlots) { + JSString *str; + + str = JSVAL_TO_STRING(aID); + + const jschar *chars = ::JS_GetStringChars(str); + const PRUnichar *unichars = NS_REINTERPRET_CAST(const PRUnichar*, chars); + + if (!nsCRT::strcmp(unichars, NS_LITERAL_STRING("src").get())) { + // Someone is trying to resolve "src" so we deifine it on the + // object with a JSVAL_VOID value, the real value will be returned + // when the caller calls GetProperty(). + ::JS_DefineUCProperty(aContext, + (JSObject *)mInner.mDOMSlots->mScriptObject, + chars, ::JS_GetStringLength(str), + JSVAL_VOID, nsnull, nsnull, 0); + + return PR_TRUE; + } + } + return mInner.Resolve(aContext, aObj, aID); } diff --git a/layout/html/content/src/nsHTMLImageElement.cpp b/layout/html/content/src/nsHTMLImageElement.cpp index 5d5bee4270c6..6df08b6d9a91 100644 --- a/layout/html/content/src/nsHTMLImageElement.cpp +++ b/layout/html/content/src/nsHTMLImageElement.cpp @@ -725,6 +725,27 @@ nsHTMLImageElement::EnumerateProperty(JSContext *aContext, JSObject *aObj) PRBool nsHTMLImageElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID) { + if (JSVAL_IS_STRING(aID) && mInner.mDOMSlots) { + JSString *str; + + str = JSVAL_TO_STRING(aID); + + const jschar *chars = ::JS_GetStringChars(str); + const PRUnichar *unichars = NS_REINTERPRET_CAST(const PRUnichar*, chars); + + if (!nsCRT::strcmp(unichars, NS_LITERAL_STRING("src").get())) { + // Someone is trying to resolve "src" so we deifine it on the + // object with a JSVAL_VOID value, the real value will be returned + // when the caller calls GetProperty(). + ::JS_DefineUCProperty(aContext, + (JSObject *)mInner.mDOMSlots->mScriptObject, + chars, ::JS_GetStringLength(str), + JSVAL_VOID, nsnull, nsnull, 0); + + return PR_TRUE; + } + } + return mInner.Resolve(aContext, aObj, aID); }