Closed Bug 254915 Opened 20 years ago Closed 20 years ago

Broken "this" for name() calls (CVS tip regression)

Categories

(Rhino Graveyard :: Core, defect)

head
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: igor, Assigned: igor)

Details

Attachments

(1 file)

Consider this test case:

/////////////////START/////////////////////////////////
var expect = "something";

var with_seed = new String(expect);
with_seed.valueOf2 = String.prototype.valueOf;

var value;
with (with_seed) {
	with (new Object) {
		value = valueOf2();
	}
}

if (value === expect) {
	print("OK");
} else {
	print("FAILED!");
}
	
/////////////////END///////////////////////////////////

With CVS tip from 2004-08-09 instead of expected OK it generates:

js: "test.js", line 12: uncaught JavaScript runtime exception: TypeError: Method
"valueOf" called on incompatible object.

The reason for this is that during evaluation of valueOf2() inside the with
statement the code correctly locates valueOf2 in with_seed object. But then
during function call it uses the nearest with object (new Object in this case)
as "this" for the function.
The fix moves all the essential code from getNameFunctionAndThis into name() in
ScriptRuntime  where code has access to the proper scope information.

I also removed no longer used ScriptRuntime.getBase and made setName to take an
extra scope parameter for proper location of the top scope when bound argument
is null.
I committed the fix
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.5R6
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: