Script() result has no prototype and scope chains

RESOLVED FIXED in 1.5R5

Status

RESOLVED FIXED
15 years ago
15 years ago

People

(Reporter: igor, Assigned: igor)

Tracking

other
1.5R5

Details

Attachments

(1 attachment)

(Assignee)

Description

15 years ago
When Script object is called as a function, its result does not have properly
initialized prototype and scope chains so various Script.prototype methods
including toString does not work.

For example, calling 
var s = Script("1;");
print(s.__proto__ != null)
print(s.__parent__ != null)
print(s)

gives 
false
false
js: "<command>", line 3: uncaught JavaScript exception:
java.lang.RuntimeException: org.mozilla.javascript.PropertyException:
Constructor for "TypeError" not found.

instead of expected: 
true
true

1;

This is a semi-regression in rhino CVS compared with Rhino 1.5 Release 4.1 since
there the bug is only present in the interpreter.

Note that calling Script as a constructor works without any problems.
(Assignee)

Comment 1

15 years ago
The propagation of the bug into the optimizer happens during changes to make
optimizer to generate single class when made code for Script initialization
shared between compiler and interpreter. 
Status: NEW → ASSIGNED
(Assignee)

Comment 2

15 years ago
Created attachment 132319 [details] [diff] [review]
Fix: initialize scope and prototype for Script instances in NativeScript.jsConstructor

If Script is called as a constructor, it will get the proper parent and
prototype from the generic code to initialize newly constructed objects but if
it is called as a function, then it is the responsibility of the call
implementation to do the job.
(Assignee)

Comment 3

15 years ago
I committed the fix
Status: ASSIGNED → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → FIXED

Comment 4

15 years ago
Testcase added to JS testsuite:

      mozilla/js/tests/js1_5/Scope/regress-220584.js

Before Igor's fix, failed in Rhino exactly as described above.
(Assignee)

Comment 5

15 years ago
Trageting 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.