Closed Bug 281606 Opened 20 years ago Closed 20 years ago

instanceof does not throw exception for objects not implementing [[HasInstance]] method

Categories

(Core :: JavaScript Engine, defect, P4)

x86
Linux
defect

Tracking

()

VERIFIED FIXED
mozilla1.8beta2

People

(Reporter: sukhisoul, Assigned: brendan)

Details

(Keywords: js1.5, Whiteboard: [have patch])

Attachments

(1 file)

User-Agent:       Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)
Build Identifier: 

According to specs -- section 11.8.6 of ECMA-262 -- instanceof operator
on objects NOT implementing [[HasInstance]] internal method should 
throw a TypeError exception. Hence, in the following script the
catch block must get executed, (since Math object does not implement
[[HasInstance]] method).

var varBool1;
var objNumber = new Number(5);
			
try{
    /* Math object can not be used for instantiation */
    /* Hence, TypeError */
    varBool1 = objNumber instanceof Math; 
			
}
catch(e){
    print("Exception " + e.name + "occurred");			
}



Reproducible: Always

Steps to Reproduce:
1. Copy the following script in a file, say t.js

var varBool1;
var objNumber = new Number(5);
			
try{
    /* Math object can not be used for instantiation */
    /* Hence, TypeError */
    varBool1 = objNumber instanceof Math; 
			
}
catch(e){
    print("Exception " + e.name + "occurred");			
}


2. Launch Spidermonkey shell with above script-file as input. eg. js t.js

3. Watch the output on the screen

Actual Results:  
Nothing was printed on screen


Expected Results:  
Should have printed following:

Exception TypeError occurred
Assignee: general → brendan
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: js1.5
Priority: -- → P4
Target Milestone: --- → mozilla1.8beta2
Reporter: no need for "STD Non-Compliance: " at the start of the summary.

/be
Status: NEW → ASSIGNED
Summary: STD Non-Compliance: instanceof does not throw exception for objects not implementing [[HasInstance]] method → instanceof does not throw exception for objects not implementing [[HasInstance]] method
Attached patch fixSplinter Review
Attachment #173932 - Flags: review?(shaver)
Whiteboard: [have patch]
Fixed.

Bob, do you want to take over QA Contact for "JavaScript Engine" from
pschwartau@meer.net?

/be
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
If that is ok with Phil, I would be happy to be qa.
the second testcase in ecma_2/instanceof/instanceof-003.js is invalid.
o = {}; o instanceof o
the second testcase in js/tests/ecma_2/instanceof/regress-7635.js is a repeat of
the o = {}; o instanceof o which is invalid after this bug fix. checked in.

js/tests/js1_5/Regress/regress-281606.js checked in with Milind
<sukhisoul@yahoo.com> as primary contributor.
/cvsroot/mozilla/js/tests/ecma_2/instanceof/instanceof-003.js,v  <-- 
instanceof-003.js
new revision: 1.2; previous revision: 1.1
Flags: testcase+
verified fixed 1.8.0.2,1.8,1.9a1 20060401 win/mac/linux
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: