-
-
Notifications
You must be signed in to change notification settings - Fork 670
Make Rtrace ESM by default, with UMD fallback #1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
this.decrementCount = 0; // The following hooks cannot just be on the prototype but must be | ||
// bound so the Rtrace instance can be used as a WebAssembly import. | ||
|
||
this.onalloc = this.onalloc.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about use arrow functions instead bindings?
instead this.load_val_i32 = this.load_val_i32.bind(this)
just use later:
load_val_i32 = (id, value) => {
return value;
}
and for rest methods use the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean moving all of the declarations into the ctor like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just remove this.load_val_i32 = this.load_val_i32.bind(this)
and friends and bind this via arrow function during declaration like:
class RTrace {
....
onresize = () => {
...
}
load_val_i32 = (id, value) => {
return value;
}
....
}
instead:
class RTrace {
constructor() {
this.onresize = this.onresize.bind(this);
this.load_val_i32 = this.load_val_i32.bind(this);
}
....
onresize() {
....
}
load_val_i32(id, value) {
return value;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, how would that look for
load_ptr(id, bytes, offset, address) {
this.accessShadow(address + offset, bytes, true);
return address;
}
when this
is accessed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that bind
ing the functions makes them usable without a proper this
context, i.e. as a Wasm import that naturally loses the this
context. Wondering if that'd still work when not bind
ing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance methods defined via arrow function grabbed current context (this of class or object). It's typical alternative for this.method = this.method.bind(this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm
SyntaxError: unknown: Support for the experimental syntax 'classProperties' isn't currently enabled (179:11):
177 | // Runtime instrumentation
178 |
> 179 | onalloc = (ptr) => {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, class properties should work since V8 7.2
or even earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's a Babel-ish error. May I suggest to make this a follow-up? Otherwise sounds good if it works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For babel you should just add this: https://babeljs.io/docs/en/babel-plugin-syntax-class-properties. It add only syntax for parser, but don't do actually transformation (lowering)
Co-authored-by: Max Graey <[email protected]>
Does what #1513 did for the loader for RTrace as well.