Skip to content

Commit

Permalink
fix: fix HostClass instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jul 29, 2021
1 parent 1a4cf54 commit c72a1b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions bridge/bindings/jsc/DOM/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using namespace foundation;
void bindElement(std::unique_ptr<JSContext> &context) {
auto element = JSElement::instance(context.get());
JSC_GLOBAL_SET_PROPERTY(context, "Element", element->classObject);
JSC_GLOBAL_SET_PROPERTY(context, "HTMLElement", element->classObject);
}

std::vector<JSStringRef> &JSElementAttributes::getAttributePropertyNames() {
Expand Down
4 changes: 2 additions & 2 deletions bridge/bindings/jsc/host_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ bool HostClass::proxyHasInstance(JSContextRef ctx, JSObjectRef constructor, JSVa

JSObjectRef instanceObject = JSValueToObject(ctx, possibleInstance, exception);
auto constructorHostClass = static_cast<HostClass *>(JSObjectGetPrivate(constructor));
auto instanceHostClass = static_cast<HostClass *>(JSObjectGetPrivate(instanceObject));
auto instanceHostClass = static_cast<Instance *>(JSObjectGetPrivate(instanceObject));

if (constructorHostClass == nullptr || instanceHostClass == nullptr) return false;
return constructorHostClass == instanceHostClass;
return instanceHostClass->prototype<HostClass>() == constructorHostClass;
}

JSObjectRef HostClass::proxyCallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount,
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/specs/dom/elements/div.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ describe('Tags div', () => {

await snapshot();
});

it('instanceof HTMLElement', () => {
let div = document.createElement('div');
expect(div instanceof Element).toBe(true);
expect(div instanceof HTMLElement).toBe(true);

});
});

0 comments on commit c72a1b0

Please sign in to comment.