Closed Bug 245113 Opened 21 years ago Closed 21 years ago

instanceof operator returns true for class prototype

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.7final

People

(Reporter: jerfa, Assigned: brendan)

Details

(Keywords: js1.5, verified1.7, Whiteboard: fixed-aviary1.0)

Attachments

(2 files)

User-Agent: Opera/7.23 (Windows NT 5.1; U) [de] Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040514 If I add a method to a class via prototype, then call that method direct via "class.prototype.method()", "this instanceof class" is true. In Opera and IE it is false. Here is the testcase: var res=""; Date.prototype.test = function() { res += (this instanceof Date)+" "; } String.prototype.test = function() { res += (this instanceof String)+" "; } res += (Date.prototype.test instanceof Date)+" "; Date.prototype.test(); String.prototype.test(); (new Date()).test(); (new String()).test(); alert(res); Reproducible: Always Steps to Reproduce: 1. Run the testcase Actual Results: Alert box displaying "false true true true true" Expected Results: Alert box displaying "false false false true true"
ECMA-262 Edition 3 agrees with comment 0. /be
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: js1.5
Summary: instanceof operator returns true when it shouldn't → instanceof operator returns true for class prototype
Assignee: general → brendan
Flags: blocking1.7+
OS: Windows XP → All
Priority: -- → P1
Hardware: PC → All
Target Milestone: --- → mozilla1.7final
Attached patch proposed fixSplinter Review
Easy patch, the bug here is specific to the brutal-sharing hack in fun_hasInstance, whereby /hi/ instanceof RegExp is true even if /hi/ was precompiled using a different RegExp object from the one used at runtime. /be
Attachment #149863 - Flags: approval1.7?
Attachment #149863 - Flags: approval1.7? → approval1.7+
Fixed on trunk and 1.7 branch. /be
Status: NEW → RESOLVED
Closed: 21 years ago
Keywords: fixed1.7
Resolution: --- → FIXED
Whiteboard: needed-aviary1.0
Works for me with rv:1.8a2 Gecko/20040603. Can I mark the bug as verified myself or should a QA person do that?
Erik: go for it, thanks! /be
Status: RESOLVED → VERIFIED
Whiteboard: needed-aviary1.0 → fixed-aviary1.0
Keywords: fixed1.7verified1.7
Erik, with your permission this will be included in the javascript test suite.
You have my permission for this test and the tests in bug 274035 and bug 244470.
js1_5/Regress/regress-245113.js checked in.
Flags: testcase+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: