Skip to content

Commit

Permalink
wasm gc: fix support of cast/instanceof for JS types; fix accessing t…
Browse files Browse the repository at this point in the history
…op-level declarations
  • Loading branch information
konsoletyper committed Oct 2, 2024
1 parent a291eb3 commit 551f050
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ TeaVM.wasm = function() {
appendToArray: (array, e) => array.push(e),
unwrapBoolean: value => value ? 1 : 0,
wrapBoolean: value => !!value,
getProperty: (obj, prop) => obj[prop],
getPropertyPure: (obj, prop) => obj[prop],
getProperty: (obj, prop) => obj !== null ? obj[prop] : getGlobalName(prop),
getPropertyPure: (obj, prop) => obj !== null ? obj[prop] : getGlobalName(prop),
setProperty: (obj, prop, value) => obj[prop] = value,
setPropertyPure: (obj, prop) => obj[prop] = value,
global: getGlobalName,
Expand Down Expand Up @@ -265,6 +265,8 @@ TeaVM.wasm = function() {
}
},
isPrimitive: (value, type) => typeof value === type,
instanceOf: (value, type) => value instanceof type,
instanceOfOrNull: (value, type) => value === null || value instanceof type,
sameRef: (a, b) => a === b,
hashCode: (obj) => {
if (typeof obj === "object" || typeof obj === "function" || typeof obj === "symbol") {
Expand Down Expand Up @@ -293,7 +295,8 @@ TeaVM.wasm = function() {
for (let i = 0; i < 32; ++i) {
imports.teavmJso["createFunction" + i] = (...args) => new Function(...args);
imports.teavmJso["callFunction" + i] = (fn, ...args) => fn(...args);
imports.teavmJso["callMethod" + i] = (instance, method, ...args) => instance[method](...args);
imports.teavmJso["callMethod" + i] = (instance, method, ...args) =>
instance !== null ? instance[method](...args) : getGlobalName(method)(...args);
imports.teavmJso["construct" + i] = (constructor, ...args) => new constructor(...args);
}
}
Expand Down
2 changes: 2 additions & 0 deletions jso/impl/src/main/java/org/teavm/jso/impl/JS.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,12 @@ public static native JSObject construct(JSObject cls, JSObject a, JSObject b, JS

@InjectedBy(JSNativeInjector.class)
@NoSideEffects
@Import(name = "instanceOf", module = "teavmJso")
public static native boolean instanceOf(JSObject obj, JSObject cls);

@InjectedBy(JSNativeInjector.class)
@NoSideEffects
@Import(name = "instanceOfOrNull", module = "teavmJso")
public static native boolean instanceOfOrNull(JSObject obj, JSObject cls);

@InjectedBy(JSNativeInjector.class)
Expand Down

0 comments on commit 551f050

Please sign in to comment.