Skip to content
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

Share more code/ideas between JsBuiltIns and Intl #5698

Merged
merged 11 commits into from
Sep 17, 2018

Conversation

jackhorton
Copy link
Contributor

Fixes #5644
Fixes #5643
Fixes an unlogged issue where all JsBuiltIns were constructable by default.

This mainly merged a lot of the code between tagPublicLibraryFunction, registerFunction, and registerChakraLibraryFunction. However, there are a number of smaller updates too:

  1. Stopped creating a new ScriptFunction on each JsBuiltIn registration. As far as I can tell, the only reason this existed before was to get a ScriptFunction without any framedisplay/environment, but since that can be set manually, its cheaper to just set it on the existing ScriptFunction.
  2. Intl functions no longer have to duplicate their name in the tagPublicLibraryCode argument and in script. I have edited a few Intl functions to confirm it works -- not sure if its worth it to go through and make all of the functions anonymous now. I also wanted to investigate changing JavascriptLibrary::InitializeFunction to not set the name attribute for these anonymous jsbuiltin functions since the name will always be overridden, but I am not sure if its possible.
  3. function length is now set using default parameters rather than manually/after the fact. Not sure if I like this better or worse than having the function macro list the length and have it set it explicitly. We could theoretically do the same optimization in InitializeFunction to avoid the extra property set.
  4. JsBuiltIns now uses a shared/projected enum for function registration like Intl.
  5. Ran into an error when using default parameters for functions marked explicitly as "use strict," and I found the error message misleading, so I changed it to be the same as V8's which I found clearer.
  6. CheckArrayAndGetLen never hit its error case and reported a slightly worse-looking runtime/accidental error as a result when this == null

Still need to run this through test262 to make sure there are no regressions.

@jackhorton jackhorton added the Bytecode-Update This PR updates bytecode and will cause merge conflicts with other PRs with this label label Sep 12, 2018
@jackhorton
Copy link
Contributor Author

Also cc @rhuanjl as the writer of so many of these builtins :)

@@ -88,7 +88,7 @@ LSC_ERROR_MSG( 1077, ERRDestructNotInit, "Destructuring declarations cannot have
LSC_ERROR_MSG(1079, ERRInvalidNewTarget, "Invalid use of the 'new.target' keyword")
LSC_ERROR_MSG(1080, ERRForInNoInitAllowed, "for-in loop head declarations cannot have an initializer")
LSC_ERROR_MSG(1081, ERRForOfNoInitAllowed, "for-of loop head declarations cannot have an initializer")
LSC_ERROR_MSG(1082, ERRNonSimpleParamListInStrictMode, "Cannot apply strict mode on functions with non-simple parameter list")
Copy link
Contributor

Choose a reason for hiding this comment

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

This change requires some baseline/test expectation updates it seems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I had only tested the array folder before putting it up last night because I was tired.

@@ -8,6 +8,7 @@ STRING(Quotes, _u("\"\""))
STRING(Whack, _u("/"))
STRING(CommaDisplay, _u(","))
STRING(CommaSpaceDisplay, _u(", "))
STRING(Dot, _u("."))
Copy link
Contributor

Choose a reason for hiding this comment

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

What uses this? I don't see any other references in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its used when building up the full display string as library->GetDotString()

Copy link
Contributor

@sigatrev sigatrev left a comment

Choose a reason for hiding this comment

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

The more code we can share between these, the better.

@rhuanjl
Copy link
Collaborator

rhuanjl commented Sep 12, 2018

Thanks for tagging me.

This looks like some very nice cleanup - also nice to see the stack trace issues fixed.

Copy link
Contributor

@sethbrenith sethbrenith left a comment

Choose a reason for hiding this comment

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

:shipit:

if (args.Info.Count == 4)
{
AssertOrFailFast(JavascriptBoolean::Is(args.Values[3]));
isConstructor = JavascriptBoolean::UnsafeFromVar(args.Values[3])->GetValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use ::FromVar and drop the AssertOrFailFast ::Is checks in this function in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got into a pattern with it in Intl as a modification of what was already there and then didn't think about it more. Combined with operator[] for ArgumentsReader, we could probably get rid of all of the arguments-related asserts... may make that a future PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure; can you put up an issue to have the failfast in ArgumentsReader operator[]? That'd be a pretty good change to have.

@chakrabot chakrabot merged commit 0accefd into chakra-core:master Sep 17, 2018
chakrabot pushed a commit that referenced this pull request Sep 17, 2018
…d Intl

Merge pull request #5698 from jackhorton:jsbuiltins/cleanup

Fixes #5644
Fixes #5643
Fixes an unlogged issue where all JsBuiltIns were constructable by default.

This mainly merged a lot of the code between tagPublicLibraryFunction, registerFunction, and registerChakraLibraryFunction. However, there are a number of smaller updates too:
1. Stopped creating a new ScriptFunction on each JsBuiltIn registration. As far as I can tell, the only reason this existed before was to get a ScriptFunction without any framedisplay/environment, but since that can be set manually, its cheaper to just set it on the existing ScriptFunction.
1. Intl functions no longer have to duplicate their name in the tagPublicLibraryCode argument and in script. I have edited a few Intl functions to confirm it works -- not sure if its worth it to go through and make all of the functions anonymous now. I also wanted to investigate changing JavascriptLibrary::InitializeFunction to not set the name attribute for these anonymous jsbuiltin functions since the name will always be overridden, but I am not sure if its possible.
1. function length is now set using default parameters rather than manually/after the fact. Not sure if I like this better or worse than having the function macro list the length and have it set it explicitly. We could theoretically do the same optimization in InitializeFunction to avoid the extra property set.
1. JsBuiltIns now uses a shared/projected enum for function registration like Intl.
1. Ran into an error when using default parameters for functions marked explicitly as "use strict," and I found the error message misleading, so I changed it to be the same as V8's which I found clearer.
1. CheckArrayAndGetLen never hit its error case and reported a slightly worse-looking runtime/accidental error as a result when this == null

Still need to run this through test262 to make sure there are no regressions.
@dilijev
Copy link
Contributor

dilijev commented Sep 17, 2018

FWIW LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bytecode-Update This PR updates bytecode and will cause merge conflicts with other PRs with this label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants