ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

An issue about evaluating instanceof

Open NWU-NISL opened this issue 4 years ago • 8 comments

According 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

NWU-NISL avatar Sep 25 '20 03:09 NWU-NISL

This Bug would be a good first issue for a new or beginning contributor to dig into, would need to investigate JavascriptOperators::OP_IsInst and see how/through what path it can fail to check prototypes for an @@hasInstance tag.

Also whilst doing it the switch IsES6HasInstanceEnabled which appears there should be removed from the codebase - check #6415 for info on removing switches.

rhuanjl avatar Dec 16 '20 22:12 rhuanjl

Hello! This sounds interesting to me, can i pick this up?

prabhatmishra33 avatar Oct 10 '21 12:10 prabhatmishra33

Go for it, tag me for any questions and review.

Please note that before I can accept a PR you'll need to add your name to the contributor agreement (as part of the PR) and include a working test for the fix as part of the PR.

rhuanjl avatar Oct 11 '21 10:10 rhuanjl

Sure Thanks @rhuanjl

prabhatmishra33 avatar Oct 11 '21 18:10 prabhatmishra33

Hi, @rhuanjl I am a bit lost in the codebase, even having a hard time in setting up a visual studio. Could you please guide me as a step1 as-in from where I should start? Now-a-days i am mostly working in javascript technologies, i hope the changes above related to the same.

prabhatmishra33 avatar Dec 19 '21 13:12 prabhatmishra33

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.

rhuanjl avatar Dec 19 '21 13:12 rhuanjl

Hi @rhuanjl, I have installed the VS-17 and facing the below issues, when i build the project:

c:\program files (x86)\windows kits\10\include\10.0.10240.0\um\winnt.h(20573): error C3861: '__readfsdword': identifier not found c:\program files (x86)\windows kits\10\include\10.0.10240.0\um\winbase.h(8756): error C3861: '_InterlockedIncrement': identifier not found

There are 1351 such errors could you please help to resolve them? I have also checked on the internet for the same, couldn't find the exact issue,

prabhatmishra33 avatar Dec 27 '21 07:12 prabhatmishra33

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

rhuanjl avatar Jan 22 '22 11:01 rhuanjl