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

Reflect.getPrototypeOf(TypeError) should return the Error prototype #5065

Closed
gfablima opened this issue Apr 30, 2018 · 9 comments
Closed

Reflect.getPrototypeOf(TypeError) should return the Error prototype #5065

gfablima opened this issue Apr 30, 2018 · 9 comments
Assignees
Milestone

Comments

@gfablima
Copy link

Hi everyone,

when we try to get the prototype of an TypeError with Reflect.getPrototypeOf(TypeError) or Object.getPrototypeOf(TypeError) is expected that these functions should return the Error function.

OS: Ubuntu 16.04 x86
Chakra: 1.9

Step to reproduce:

var protoOfError = Reflect.getPrototypeOf(TypeError);
if (!(protoOfError === Error)){
  throw new Error('expected: function Error() {[native code]}, got: ' + protoOfError);
}

Actual results:
expected: function Error() {[native code]}, got: function () {[native code]}

Expected results:
pass without failures

Same occurs with RangeError, EvalError, ReferenceError, SyntaxError and URIError.

V8, SpiderMonkey and JavascriptCore work as expected.

@fatcerberus
Copy link
Contributor

fatcerberus commented Apr 30, 2018

#/runtime/assert.mjs:33 module()
(ssj) e Reflect.getPrototypeOf(TypeError).toString()
= "function Error() { [native code] }"

#/runtime/assert.mjs:33 module()
(ssj) e Reflect.getPrototypeOf(TypeError) === Error
= true

Behavior looks correct to me.

@jackhorton
Copy link
Contributor

@gfablima , were you running this test using Node-ChakraCore? If so, I believe this may be caused by our monkey-patching of the error object in order to support custom V8 APIs.

@gfablima
Copy link
Author

gfablima commented May 1, 2018

I don't know if I'm running node-chakracore. I got the binary from master branch, running "./build.sh --static"

@digitalinfinity digitalinfinity self-assigned this May 2, 2018
@digitalinfinity
Copy link
Contributor

@fatcerberus what version of ChakraCore were you testing on? I can reproduce on a recent build:

print(Reflect.getPrototypeOf(TypeError).toString());
print(Reflect.getPrototypeOf(TypeError) === Error);
function() {
    [native code]
}
false

Assigning to myself for now to investigate

@digitalinfinity
Copy link
Contributor

It looks like this is controlled by the flag -ES6PrototypeChain which is defined as false in https://github.com/Microsoft/ChakraCore/blob/master/lib/Common/ConfigFlagsList.h#L613. I'm going to have to ask around as to why this is false- if I run ch -ES6PrototypeChain test.js the test behaves similar to other engines. Without that flag, error constructor functions are provided the function prototype as their prototypes.

@fatcerberus
Copy link
Contributor

Ah, that explains it: My runtime initialization includes JsRuntimeAttributeEnableExperimentalFeatures which presumably enables that flag (and, well, everything else).

@digitalinfinity
Copy link
Contributor

@fatcerberus that makes sense 😄 - I'll follow up on whether we can turn this on by default. @gfablima does @fatcerberus's pattern work for you?

@dilijev dilijev added the Bug label May 2, 2018
@gfablima
Copy link
Author

gfablima commented May 2, 2018

Hi @fatcerberus and @digitalinfinity.
Thanks for this workaround, it works with the flag -ES6PrototypeChain

@digitalinfinity
Copy link
Contributor

Change is ready but the compat risk is high for 1.10- moving to vNext so that we have additional cushion for compat testing

@digitalinfinity digitalinfinity modified the milestones: 1.10, vNext Aug 1, 2018
chakrabot pushed a commit that referenced this issue Sep 11, 2018
We want to enable the `-Es6PrototypeChain` flag by default to support the spec better. Most of this PR is updating test baselines.

Fixes #5065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants