-
Notifications
You must be signed in to change notification settings - Fork 686
Implement computed properties for object literals. #2481
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
559180f to
5b13d44
Compare
|
Patch is done, and ready for review. |
LaszloLango
left a comment
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.
Please update the snapshot version
jerry-core/vm/vm.h
Outdated
| VM_OC_PUSH_LIT_NEG_BYTE, /**< push literal and number between -1 and -256 */ | ||
| VM_OC_PUSH_OBJECT, /**< push object */ | ||
| VM_OC_SET_PROPERTY, /**< set property */ | ||
| #ifndef CONFIG_DISABLE_ES2015_OBJECT_LITERAL |
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.
Please do not use #ifndef in this enum. It can cause errors in snapshot execution with different build configurations.
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.
This is reworked in the execution engine. Now the byte codes are translated to a valid VM opcode or a fatal error. This is much safer now, since we at least get an error rather than a random crash if we execute a snapshot with invalid byte codes. Normally this should be detected early, but we have a safety net now.
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.
OK
|
Come to think of snapshots, I also increased the snapshot version number. |
5b13d44 to
95943e7
Compare
LaszloLango
left a comment
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.
LGTM
| [fxy()] () { | ||
| return 6; | ||
| } | ||
|
|
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.
Please add test cases for:
class C {
["const" + "ructor"] { // 1.
this.a = 5;
}
get ["constructor"]() { // 2.
return this.a;
}
static ["prototype"] () { // 3.
return 10;
}
}In the first case it must be a normal class method instead of the real constructor of the class.
The second one is a bit similar. In normal case the get constructor() {} is not allowed for classes (the real constructor cannot be an accessor), but as a computed property name it must be a simple accessor with constructor name.
Finally, the third one must throw a TypeError in runtime as the same way as static prototype () {} throws a SyntaxError during the script parsing.
|
|
||
| if (ECMA_IS_VALUE_ERROR (result)) | ||
| { | ||
| goto error; |
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.
If the result is an error, should not the left_value be freed?
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.
The error handling automatically frees both left and right values.
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.
OK, thanks for clarifying it.
jerry-core/config.h
Outdated
| # define CONFIG_DISABLE_ES2015_ARROW_FUNCTION | ||
| # define CONFIG_DISABLE_ES2015_CLASS | ||
| # define CONFIG_DISABLE_ES2015_BUILTIN | ||
| # define CONFIG_DISABLE_ES2015_OBJECT_LITERAL |
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.
It is a new feature, so please update the profile documentation.
95943e7 to
ef88df9
Compare
|
Thank you for the review. Some bigger changes applied, @LaszloLango you might want to take another look (I changed literal to initializer, because es6 uses this term and reworked property setting in the vm). New tests added as well. |
rerobika
left a comment
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.
LGTM (informal)
|
@zherczeg Ok, I will take a look on the changes. |
ef88df9 to
f2d469e
Compare
|
still LGTM |
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.
Left some minor comments.
Thanks for helping out by the way!
|
|
||
| #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER | ||
| #error "Class support requires ES2015 object literal support" | ||
| #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */ |
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.
If we're making this a requirement, should maybe this code be moved to config.h?
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.
I searched through the code base and only a few #error is there. It seems there is a configuration check in the normal code base:
https://github.com/jerryscript-project/jerryscript/blob/master/jerry-core/jcontext/jcontext.h#L194
But config.h also have a check.
https://github.com/jerryscript-project/jerryscript/blob/master/jerry-core/config.h#L81
The truth is I don't know we have a policy for that. It depends config.h is mandatory, or user supplied. Anybody knows 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.
(In most projects I know config.h is auto generated, and contains no dependency checks. In JerryScript config.h is not auto generated.)
| } | ||
|
|
||
| parser_stack_pop_uint8 (context_p); | ||
| #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */ |
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.
Shouldn't this be /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */?
Also disable ES5.1 property name dumplication checks when ES2015 object literals are enabled. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
f2d469e to
ec4f18c
Compare
robertsipka
left a comment
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.
LGTM
Refs: jerryscript-project/jerryscript#2431 Refs: jerryscript-project/jerryscript#2496 Refs: jerryscript-project/jerryscript#2485 Refs: jerryscript-project/jerryscript#2530 Refs: jerryscript-project/jerryscript#2547 Refs: jerryscript-project/jerryscript#2436 Refs: jerryscript-project/jerryscript#2467 Refs: jerryscript-project/jerryscript#2481 Refs: jerryscript-project/jerryscript#2408 Refs: jerryscript-project/jerryscript#2430 Refs: jerryscript-project/jerryscript#2439 Refs: jerryscript-project/jerryscript#2588
No description provided.