-
Notifications
You must be signed in to change notification settings - Fork 309
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
Feature/super expression #468
Feature/super expression #468
Conversation
The enabled JSOperations are: CallSuperConstructor, SetSuperProperty, GetSuperProperty, SetComputedSuperProperty, GetComputedSuperProperty, CallSuperMethod, UpdateSuperProperty
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.
Very nice, thanks! Just one question/suggestion
@@ -1633,7 +1633,7 @@ final class CallSuperConstructor: JsOperation { | |||
} | |||
|
|||
init(numArguments: Int) { | |||
super.init(numInputs: numArguments, firstVariadicInput: 0, attributes: [.isVariadic, .isCall], requiredContext: [.javascript, .method]) | |||
super.init(numInputs: numArguments, numOutputs: 1, firstVariadicInput: 0, attributes: [.isVariadic, .isCall], requiredContext: [.javascript, .method]) |
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.
Why this change? Do we need to handle the return value of this, or could we just convert it to this
instead if we really need it? (AFAIK the return value will just be this
)
guard !callSuperConstructor.isOptional else { | ||
throw CompilerError.unsupportedFeatureError("Optional chaining is not supported in super constructor calls") | ||
} | ||
return emit(CallSuperConstructor(numArguments: arguments.count), withInputs: arguments).output |
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.
Is this why you need CallSuperConstructor
to now return a value? I wonder if we should just do this instead:
// The "return" value of invoking the super constructor is just |this|
emit(CallSuperConstructor(numArguments: arguments.count), withInputs: arguments)
return emit(LoadThis())
WDYT?
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.
Ah even simpler, I think you can just do return lookupIdentifier("this");
since this
must be available inside class constructors/methods (see
map("this", to: parameters.removeFirst()) |
Nice, thanks! 🎉 |
The enabled JSOperations are: CallSuperConstructor, SetSuperProperty, GetSuperProperty, SetComputedSuperProperty, GetComputedSuperProperty, CallSuperMethod, UpdateSuperProperty
With this, 7 new JSOperations become compilable:
I verified correctness with Tests/FuzzilliTests/CompilerTests/super.js
Lifts to semantically equivalent code. (No side effects like with delete).
It is probably not a lot of effort to implement the remaining super cases but it is lower down the priority list.