All users were logged out of Bugzilla on October 13th, 2018

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

RESOLVED FIXED in 1.6R1

Status

RESOLVED FIXED
14 years ago
14 years ago

People

(Reporter: igor, Assigned: igor)

Tracking

Details

Attachments

(1 attachment)

(Assignee)

Description

14 years ago
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.
(Assignee)

Comment 1

14 years ago
Created attachment 155604 [details] [diff] [review]
Fix: proper name lookup

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.
(Assignee)

Comment 2

14 years ago
I committed the fix
Status: NEW → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.5R6
You need to log in before you can comment on or make changes to this bug.