An issue about evaluating instanceof
See original GitHub issueAccording to ES10.0, If an object does not define or inherit @@hasInstance
it uses the default instanceof
semantics. When changing the value of __proto__
of an object into String
, the algorithm to be used will be Function.prototype [ @@hasInstance ]
instead of the default semantics. So the output of the testcase below is false
as other engines do. This may be an issue of chakra.
version
v1.11.19
command
chakra/cc_linux_x64_1_11_19/ChakraCoreFiles/bin/ch testcase.js
testcase
var obj = {__proto__:String};
var result = "hello" instanceof obj;
print(result);
output
TypeError: obj is not a function. (evaluating '"hello" instanceof obj')
expected output
false
contributor:@YuanWangC
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
Why does instanceof evaluate to true here? - Stack Overflow
The instanceof operator tests whether an object in its prototype chain has the prototype property of a constructor. I would expect that (f ......
Read more >TypeError: invalid 'instanceof' operand 'x' - JavaScript | MDN
The JavaScript exception "invalid 'instanceof' operand" occurs when the right-hand side operands of the instanceof operator isn't used with ...
Read more >Java static code analysis: Operator "instanceof" should be ...
The instanceof construction is a preferred way to check whether a variable can be cast to some type statically because a compile-time error...
Read more >Java instanceof Operator - Baeldung
instanceof is a binary operator we use to test if an object is of a given type. The result of the operation is...
Read more >Static evaluation of instanceof and in statements causing errors
I have a couple functions that look like this: function tryJSON( value ) { try { return JSON.parse( value ); } catch( err...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
1st. Can you build ChakraCore? If you’re on windows point visual studio at Build\Chakra.Core.sln Check that you can build it, I reccomend the x64 debug configuration for testing.
2nd. Make a javascript file that reproduces the above error, run it from the command line with
ch.exe
(which will have been built as part of step 1)3rd. Have a look in the ChakraCore codebase for JavascriptOperators::OP_IsInst (it’s in the file: lib/Runtime/Language/JavascriptOperators.cpp) explore what this function is doing and how/when/why it can fail to check an object’s prototype. (This may not be the source of the error - but it appears to be at first glance), you’ll probably need to repeatedly rebuild and test examples with
ch.exe
to figure out how to get this working properly.4th. If you can get it working you’ll need to add a suitable test to our test suite - tag me for help again there if it’s not obvious how to do it.
I’m sorry I’ve been away and didn’t see this message, I’m not familiar with these errors, you may be trying to build with too new a windows RT or something. If you’re still interested, please can you try building with the ci build script?
Open a developer command line and run
test/ci.buildone.cmd x64 test