Ticket #78 (new defect)

Opened 2 years ago

Last modified 1 year ago

The 'this' constraint on functions is not being checked.

Reported by: lth Assigned to: anonymous
Type: defect Priority: minor
Milestone: M1 Component: RefImpl
Version: 4 Keywords:
Cc:

Description

The following code ought to signal an error because the toString method has a this constraint:

>> var tostr = String.prototype.toString
>> var astring = new Number()
>> astring.toString = tostr
>> astring.toString()
0

(At the moment I've added a simple check in the function itself so that the error is thrown, but this is a bug.)

Attachments

Change History

Changed 1 year ago by jresig

  • summary changed from The 'this' constraint on prototype methods is not being checked. to The 'this' constraint on functions is not being checked.

This is a generic problem. See the following as well:

>> class Foo {}
>> function foo(this:Foo){ return this }
>> foo.call( new Foo() )
[object Foo]
>> foo.call( "test" )
test
Note: See TracTickets for help on using tickets.