Closed Bug 1468524 Opened 6 years ago Closed 6 years ago

Instances of TypedObject types are not 'instanceof' their constructors

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox62 --- wontfix
firefox63 --- fixed

People

(Reporter: lth, Assigned: lth)

References

Details

Attachments

(1 file)

This yields false but should not:

  var Box = new TypedObject.StructType({x:TypedObject.int32})
  var box = new Box({x:37})
  box instanceof Box

Till speculated that this might be a regression brought on by a rewrite around some hasInstance functionality.

I'm marking this as blocking the Wasm GC MVP because we probably want TypedObjects to behave sanely for that, but it's not critical for anything at this point.
We end up in fun_symbolHasInstance() which subsequently fails because OrdinaryHasInstance() finds that the this object is not callable, ie, Box() is not.  So either it should be, or it should be flagged as some kind of primitive so that the guard earlier in fun_symbolHasInstance will handle it, though the latter case seems wrong (the result would be false).

Normally constructors are callable of course.
It really is not callable:

js> var Box = new TypedObject.StructType({x:TypedObject.int32})
js> Box(1)
typein:4:1 TypeError: Box is not a function
Stack:
  @typein:4:1
A simple fix that only fixes instanceof for TypedObject struct types.  If this meets with approval I will also investigate the situation for arrays, which I suspect are similarly borked.
Assignee: nobody → lhansen
Status: NEW → ASSIGNED
Attachment #8988488 - Flags: review?(till)
Priority: -- → P1
Till, review ping?
Flags: needinfo?(till)
Also, without this fix, if we create an instance s of a StructType and then try to print s.constructor, we get an error:

  TypeError: Function.prototype.toString called on incompatible object
Comment on attachment 8988488 [details] [diff] [review]
bug1468524-typedobj-struct-instanceof.patch

Review of attachment 8988488 [details] [diff] [review]:
-----------------------------------------------------------------

Sorry for inexplicably dragging my feet on this very obvious fix :(
Attachment #8988488 - Flags: review?(till) → review+
Flags: needinfo?(till)
Pushed by lhansen@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/3858eb122b9f
Fix instanceof for TypedObject 'struct' instances. r=till
https://hg.mozilla.org/mozilla-central/rev/3858eb122b9f
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Lars, would you be able to answer Noemi's question?
Flags: needinfo?(sdetar) → needinfo?(lhansen)
Intermittents would be a strange outcome from that change, but I'll give it some attention, probably tomorrow.
Steven/Noemi, more likely the culprit is bug 1480963, which has a patch now.
Flags: needinfo?(lhansen)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: