Closed Bug 844677 Opened 12 years ago Closed 9 years ago

Need way to check class of this value in non-generic self-hosted functions

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1081435

People

(Reporter: mozillabugs, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [js:t])

Many of the standard built-in ECMAScript functions require this values of specific types. For example, ES5 15.59.5 says that for Date methods "unless explicitly noted otherwise, ... a TypeError exception is thrown if the this value is not an object for which the value of the [[Class]] internal property is 'Date'".

In C++ code, this is commonly implemented using the CallNonGenericMethod function. CallNonGenericMethod takes a test function and an implementation function, follows proxy chains for the this value if necessary, checks the this value using the test function, throws an exception if it's not of the right type and class, and calls the implementation function.

We need a solution for this problem for self-hosted code. I currently have a workaround using an intrinsic function that uses CallNonGenericMethod, but because of the additional layer it reports the wrong function name in the exception.
Whiteboard: [js:t]
I think we want to duplicate the logic from CallNonGenericMethod in an intrinsic and use ThrowError on fail.

We should be able to use a generic test function for all self-hosted standard builtins, right?
(In reply to Norbert Lindenberg from comment #0)
> I currently have a
> workaround using an intrinsic function that uses CallNonGenericMethod, but
> because of the additional layer it reports the wrong function name in the
> exception.

The workaround has changed to simply letting valueOf handle the check. Jeff noticed that valueOf was called in all self-hosted functions that currently need this capability, and includes the check (see bug 769871 comment 19). Error messages now say that "valueOf method called on incompatible ...", which is different but still wrong.
Blocks: 784288
Assignee: general → nobody
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.