Open Bug 1230640 Opened 4 years ago Updated 3 years ago

Add intrinsic for checking the DOM protochain

Categories

(Core :: JavaScript Engine, defect)

defect
Not set

Tracking

()

People

(Reporter: mwu, Assigned: mwu)

References

(Depends on 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch Add CheckDOMProtochain intrinsic (obsolete) — Splinter Review
This is useful for writing self hosting DOM. Not sure if I like the name of the intrinsic, but it seems more descriptive than instanceClassMatchesProto.

Planning to add tests after bug 1224722 lands, but I've verified that this works as expected with some simple self hosted DOM prototypes.
A few notes:

1)  The naming weirdness comes from the fact that this is not checking the actual proto chain.  It's checking whether the default proto chain for the object would have our proto on it.

2)  Do we want this to work on the level of "two integers" or "jitinfo" or "the callee function"?
(In reply to Boris Zbarsky [:bz] from comment #1)
> 1)  The naming weirdness comes from the fact that this is not checking the
> actual proto chain.  It's checking whether the default proto chain for the
> object would have our proto on it.
> 

CheckOriginalDOMProtochain? I'll take any suggestions for an alternate name. :)

> 2)  Do we want this to work on the level of "two integers" or "jitinfo" or
> "the callee function"?

This takes an object and two integers and passes them to the instanceClassMatchesProto callback set by the JSAPI user, so I assume "two integers"? In the self hosted DOM code, it looks something like:

    if (!CheckDOMProtochain(this, 112, 1))
        ThrowTypeError("\"this\" object does not implement interface Node.");
> This takes an object and two integers

Right, I did see that.

I guess if you're codegenning the caller two integers makes sense.
Yup - I have codegen that takes care of these things. For example -

function KeyboardEvent_fn_initKeyboardEvent(typeArg, bubblesArg, cancelableArg, viewArg, keyArg, locationArg, modifiersListArg, repeat, locale) {
    if (!CheckDOMProtochain(this, 106, 2))
        ThrowTypeError("\"this\" object does not implement interface KeyboardEvent.");
    if (arguments.length < 9)
        ThrowTypeError("Not enough arguments to \"KeyboardEvent.initKeyboardEvent\".");
    typeArg = ToString(typeArg);
    bubblesArg = ToBoolean(bubblesArg);
    cancelableArg = ToBoolean(cancelableArg);
    if (viewArg !== void 0 && viewArg !== null) {
        if (!CheckDOMProtochain(viewArg, 147, 1))
            ThrowTypeError("\"this\" object does not implement interface Window.");
    }
    keyArg = ToString(keyArg);
    locationArg = ToWebidlUnsignedLong(locationArg);
    modifiersListArg = ToString(modifiersListArg);
    repeat = ToBoolean(repeat);
    locale = ToString(locale);
    return KeyboardEventImpl_fn_initKeyboardEvent(new KeyboardEvent(this), typeArg, bubblesArg, cancelableArg, viewArg, keyArg, locationArg, modifiersListArg, repeat, locale);
}
This adds some inlining support. Haven't had a chance to check if it actually works, but it compiles. Putting it here in case someone who knows how this works wants to comment on it before I get to testing it.
Attachment #8695999 - Attachment is obsolete: true
I've confirmed that the inlining support works, so I just need to figure out how to write a test for this.
You need to log in before you can comment on or make changes to this bug.