Closed Bug 203909 Opened 22 years ago Closed 22 years ago

Behavior of built-in functions called as constructors should follow standard.

Categories

(Rhino Graveyard :: Core, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: igor, Assigned: norrisboyd)

Details

Attachments

(1 file, 1 obsolete file)

This is a Rhino version of bug 202019 , see the description there.
To resolve this in a uniform way I changed BaseFunction.constructor to always call createObject and then run the call method so IdFunction and FunctionObject needs to override only createObject and not the construct method itself. Then IdFunction.createObject simply throws TypeError if the function is not explicitly marked as constructor. The current behavior of SM can be obtained if instead of throwing error, IdFunction.createObject can call super.createObject. The patch should cover all the standard library functions since all of them are implemented in terms of IdFunction and they marked as constructors only when the standard required it.
Attachment #122124 - Attachment is obsolete: true
I committed the fix, now in Rhino shell: js> new parseInt('1') js: "<stdin>", line 1: uncaught JavaScript exception: TypeError: "parseInt" is not a constructor. (<stdin>; line 1) js> new String.prototype.toString() js: "<stdin>", line 2: uncaught JavaScript exception: TypeError: "toString" is not a constructor. (<stdin>; line 2)
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Verified FIXED. But is the error message for |eval| correct? Rhino 1.5 release 5 0000 00 00 js> var obj = new eval(); TypeError: [object global] is not a function. Shouldn't the error message say, '"eval" is not a constructor'? COMPARE: js> var obj = new isFinite(); TypeError: "isFinite" is not a constructor. js> var obj = new Date.parse(); TypeError: "parse" is not a constructor.
Status: RESOLVED → VERIFIED
Note: Igor has fixed the error message for |new eval();| in bug 204210. See bug 204210 comment 4.
Targeting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: