Bug 824217 - Remove the JSRESOLVE_ASSIGNING test that guards definition of DOM Worker constructors and Gecko-specific script namespace manager constructors. r=bz

This commit is contained in:
Jeff Walden 2013-01-03 12:29:16 -06:00
parent 829dc7459d
commit e9191e095f
5 changed files with 154 additions and 47 deletions

View File

@ -440,6 +440,7 @@
#include "mozilla/dom/indexedDB/IDBIndex.h"
using mozilla::dom::indexedDB::IDBWrapperCache;
using mozilla::dom::workers::ResolveWorkerClasses;
#include "nsIDOMMediaQueryList.h"
@ -6552,10 +6553,6 @@ ContentWindowGetter(JSContext *cx, unsigned argc, jsval *vp)
return ::JS_GetProperty(cx, obj, "content", vp);
}
static JSNewResolveOp sOtherResolveFuncs[] = {
mozilla::dom::workers::ResolveWorkerClasses
};
template<class Interface>
static nsresult
LocationSetterGuts(JSContext *cx, JSObject *obj, jsval *vp)
@ -6740,7 +6737,6 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
nsresult rv = NS_OK;
if (sLocation_id == id) {
// This must be done even if we're just getting the value of
// window.location (i.e. no checking flags & JSRESOLVE_ASSIGNING
@ -6748,7 +6744,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// getter from being overriden (for security reasons).
nsCOMPtr<nsIDOMLocation> location;
rv = win->GetLocation(getter_AddRefs(location));
nsresult rv = win->GetLocation(getter_AddRefs(location));
NS_ENSURE_SUCCESS(rv, rv);
// Make sure we wrap the location object in the window's scope.
@ -6777,7 +6773,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (sTop_id == id) {
nsCOMPtr<nsIDOMWindow> top;
rv = win->GetScriptableTop(getter_AddRefs(top));
nsresult rv = win->GetScriptableTop(getter_AddRefs(top));
NS_ENSURE_SUCCESS(rv, rv);
jsval v;
@ -6827,9 +6823,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
jsval v;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, wrapperObj, child_win,
&NS_GET_IID(nsIDOMWindow), true, &v,
getter_AddRefs(holder));
nsresult rv = WrapNative(cx, wrapperObj, child_win,
&NS_GET_IID(nsIDOMWindow), true, &v,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
@ -6847,38 +6843,28 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
}
// It is not worth calling GlobalResolve() if we are resolving
// for assignment, since only read-write properties get dealt
// with there.
if (!(flags & JSRESOLVE_ASSIGNING)) {
JSAutoRequest ar(cx);
// Handle resolving if id refers to a name resolved by DOM worker code.
js::RootedObject tmp(cx, NULL);
if (!ResolveWorkerClasses(cx, obj, id, flags, &tmp)) {
return NS_ERROR_FAILURE;
}
if (tmp) {
*objp = tmp;
return NS_OK;
}
// Resolve special classes.
for (uint32_t i = 0; i < ArrayLength(sOtherResolveFuncs); i++) {
js::RootedObject tmp(cx, *objp);
if (!sOtherResolveFuncs[i](cx, obj, id, flags, &tmp)) {
return NS_ERROR_FAILURE;
}
*objp = tmp;
if (*objp) {
return NS_OK;
}
}
// Check for names managed by the script namespace manager. Call
// GlobalResolve() after we call FindChildWithName() so that named child
// frames will override external properties which have been registered with
// the script namespace manager -- pages must be able to depend on frame
// names working no matter how Gecko's been configured.
bool did_resolve = false;
nsresult rv = GlobalResolve(win, cx, obj, id, &did_resolve);
NS_ENSURE_SUCCESS(rv, rv);
// Call GlobalResolve() after we call FindChildWithName() so
// that named child frames will override external properties
// which have been registered with the script namespace manager.
bool did_resolve = false;
rv = GlobalResolve(win, cx, obj, id, &did_resolve);
NS_ENSURE_SUCCESS(rv, rv);
if (did_resolve) {
// GlobalResolve() resolved something, so we're done here.
*objp = obj;
return NS_OK;
}
if (did_resolve) {
*objp = obj;
return NS_OK;
}
if (s_content_id == id) {
@ -6998,11 +6984,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
}
JSObject *oldobj = *objp;
rv = nsDOMGenericSH::NewResolve(wrapper, cx, obj, id, flags, objp,
_retval);
if (NS_FAILED(rv) || *objp != oldobj) {
if (NS_FAILED(rv) || *objp) {
// Something went wrong, or the property got resolved. Return.
return rv;
}

View File

@ -11,6 +11,8 @@ relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_FILES = \
test_constructor.html \
test_constructor-assignment.html \
test_document.all_unqualified.html \
test_domrequest.html \
test_e4x_for_each.html \

View File

@ -0,0 +1,61 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
function testConstructor(name)
{
window[name] = 17; // resolve through assignment
var desc = Object.getOwnPropertyDescriptor(window, name);
ok(typeof desc === "object" && desc !== null, name + ": property must exist");
is(desc.value, 17, name + ": overwrite didn't work correctly");
is(desc.enumerable, false,
name + ": initial descriptor was non-enumerable, and [[Put]] changes " +
"the property value but not its enumerability");
is(desc.configurable, true,
name + ": initial descriptor was configurable, and [[Put]] changes the " +
"property value but not its configurability");
is(desc.writable, true,
name + ": initial descriptor was writable, and [[Put]] changes the " +
"property value but not its writability");
}
var ctors =
[
"HTMLElement",
"HTMLDivElement",
"HTMLSpanElement",
"HTMLParagraphElement",
"HTMLOptionElement",
"HTMLHtmlElement",
"Element",
"Node",
"Document",
"Image",
"Audio",
"HTMLAudioElement",
"HTMLVideoElement",
"Window",
"XMLHttpRequest",
"Navigator",
"WebSocket",
"Event",
"IDBKeyRange",
"CSSPageRule",
"SVGPatternElement",
];
ctors.forEach(testConstructor);
</script>
</body>
</html>

View File

@ -0,0 +1,61 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
function testConstructor(name)
{
window[name]; // resolve not through assignment
window[name] = 17;
var desc = Object.getOwnPropertyDescriptor(window, name);
ok(typeof desc === "object" && desc !== null, name + ": property must exist");
is(desc.value, 17, name + ": overwrite didn't work correctly");
is(desc.enumerable, false,
name + ": initial descriptor was non-enumerable, and [[Put]] changes " +
"the property value but not its enumerability");
is(desc.configurable, true,
name + ": initial descriptor was configurable, and [[Put]] changes the " +
"property value but not its configurability");
is(desc.writable, true,
name + ": initial descriptor was writable, and [[Put]] changes the " +
"property value but not its writability");
}
var ctors =
[
"HTMLElement",
"HTMLDivElement",
"HTMLSpanElement",
"HTMLParagraphElement",
"HTMLOptionElement",
"HTMLHtmlElement",
"Element",
"Node",
"Document",
"Image",
"Audio",
"HTMLAudioElement",
"HTMLVideoElement",
"Window",
"XMLHttpRequest",
"Navigator",
"WebSocket",
"Event",
"IDBKeyRange",
"CSSPageRule",
"SVGPatternElement",
];
ctors.forEach(testConstructor);
</script>
</body>
</html>

View File

@ -16,11 +16,9 @@
ok(typeof desc === "object" && desc !== null, "Worker property must exist");
is(desc.value, 17, "Overwrite didn't work correctly");
// The JSRESOLVE_ASSIGNING flag-check around the "Resolve special classes"
// block in nsWindowSH::NewResolve needs to die to enable this.
todo_is(desc.enumerable, false,
"Initial descriptor was non-enumerable, and [[Put]] changes the " +
"property value but not its enumerability");
is(desc.enumerable, false,
"Initial descriptor was non-enumerable, and [[Put]] changes the " +
"property value but not its enumerability");
is(desc.configurable, true,
"Initial descriptor was configurable, and [[Put]] changes the " +
"property value but not its configurability");