Bug 1299363 - Part 2: Allow prototype swizzling in html constructor. r=bz

MozReview-Commit-ID: KGVfbAxpbfq

--HG--
extra : rebase_source : f9b5150eb2c988b0d18b44cdcce820bc8d3f4bf3
extra : histedit_source : a6f4f69740f3622959557e1fc0ae44bb05151c37
This commit is contained in:
Edgar Chen 2017-02-17 18:33:44 +08:00
Родитель 089e114bd5
Коммит 12bce104dc
3 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -3563,7 +3563,7 @@ GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj)
// https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor
already_AddRefed<nsGenericHTMLElement>
CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,
ErrorResult& aRv)
JS::Handle<JSObject*> aGivenProto, ErrorResult& aRv)
{
// Step 1.
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
@ -3698,7 +3698,23 @@ CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,
return nullptr;
}
// Step 11 is in the code output by CGClassConstructor.
// Step 11.
// Do prototype swizzling for upgrading a custom element here, for cases when
// we have a reflector already. If we don't have one yet, our caller will
// create it with the right proto (by calling DoGetOrCreateDOMReflector with
// that proto).
JS::Rooted<JSObject*> reflector(cx, element->GetWrapper());
if (reflector) {
// reflector might be in different compartment.
JSAutoCompartment ac(cx, reflector);
JS::Rooted<JSObject*> givenProto(cx, aGivenProto);
if (!JS_WrapObject(cx, &givenProto) ||
!JS_SetPrototype(cx, reflector, givenProto)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
}
// Step 12 and Step 13.
return element.forget();
}

Просмотреть файл

@ -3373,7 +3373,7 @@ GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj);
// that constructor function.
already_AddRefed<nsGenericHTMLElement>
CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,
ErrorResult& aRv);
JS::Handle<JSObject*> aGivenProto, ErrorResult& aRv);
void
SetDocumentAndPageUseCounter(JSContext* aCx, JSObject* aObject,

Просмотреть файл

@ -7709,7 +7709,7 @@ class CGPerSignatureCall(CGThing):
argsPre.append("global")
if isConstructor and idlNode.isHTMLConstructor():
argsPre.append("args")
argsPre.extend(["args", "desiredProto"])
# For JS-implemented interfaces we do not want to base the
# needsCx decision on the types involved, just on our extended