Skip to content

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

Merged
merged 1 commit into from
Aug 28, 2018

Conversation

zherczeg
Copy link
Member

No description provided.

@zherczeg
Copy link
Member Author

zherczeg commented Aug 22, 2018

Patch is done, and ready for review.

Copy link
Contributor

@LaszloLango LaszloLango left a 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

@@ -121,6 +121,9 @@ typedef enum
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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@zherczeg
Copy link
Member Author

Come to think of snapshots, I also increased the snapshot version number.

Copy link
Contributor

@LaszloLango LaszloLango left a 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;
}

Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@@ -39,6 +39,7 @@
# define CONFIG_DISABLE_ES2015_ARROW_FUNCTION
# define CONFIG_DISABLE_ES2015_CLASS
# define CONFIG_DISABLE_ES2015_BUILTIN
# define CONFIG_DISABLE_ES2015_OBJECT_LITERAL
Copy link
Member

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.

@zherczeg
Copy link
Member Author

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.

Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (informal)

@LaszloLango
Copy link
Contributor

@zherczeg Ok, I will take a look on the changes.

@LaszloLango
Copy link
Contributor

still LGTM

Copy link
Contributor

@AnthonyCalandra AnthonyCalandra left a 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 */
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Member Author

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.)

while (context_p->stack_top_uint8 != PARSER_OBJECT_PROPERTY_START)
{
parser_stack_pop (context_p, NULL, 3);
}

parser_stack_pop_uint8 (context_p);
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
Copy link
Contributor

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 [email protected]
@akosthekiss akosthekiss added the ES2015 Related to ES2015 features label Aug 28, 2018
Copy link
Contributor

@robertsipka robertsipka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zherczeg zherczeg merged commit bd42403 into jerryscript-project:master Aug 28, 2018
@zherczeg zherczeg deleted the computed_props branch August 28, 2018 13:28
legendecas added a commit to yodaos-project/ShadowNode that referenced this pull request Nov 29, 2018
legendecas added a commit to yodaos-project/ShadowNode that referenced this pull request Nov 29, 2018
legendecas added a commit to yodaos-project/ShadowNode that referenced this pull request Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES2015 Related to ES2015 features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants