Closed Bug 117849 Opened 24 years ago Closed 24 years ago

NativeJavaMethod do not store "this" pointer.

Categories

(Rhino Graveyard :: Core, enhancement)

x86
Windows 2000
enhancement
Not set
normal

Tracking

(Not tracked)

VERIFIED INVALID

People

(Reporter: yliu000, Assigned: norrisboyd)

Details

Try the following scenario: java -classpath js.jar org.mozilla.javascript.shell.Main js> x = new java.util.Vector() js> y = x.addElement js> y('10') Then I get: js: "<stdin>", line 3: Java method "addElement" was invoked with a 'this' value that was not a Java object. I understand this is because the NativeJavaMethod do not store the "this" pointer in it, and expect the "thisObj" to be passed through the "call" function, while when I call "y('10')" the "thisObj" parameter is null. I think maybe it can be enhanced to pass in the "this" pointer when constructing the NativeJavaMethod method. Since I believe the scenario I write is totally legal. Thanks
Confirming reported behavior on WinNT, JDK 1.3
I don't know if this helps, but here is a similar example using only JavaScript objects. The array value doesn't get added, but there is no error: java org.mozilla.javascript.tools.shell.Main js> var x = new Array(); js> x.toString(); // showing that it has no elements js> js> var y = x.push; js> y('10'); 1 js> x.toString(); // it still has no elements... js>
I get the same behavior in SpiderMonkey as in additional comment #2.
ECMA specifies ways in which the 'this' pointer is resolved during a call. We aren't at liberty to change this behavior. See "11.2.3 Function Calls". The key here is the GetBase operation, which must resolve to the global object since y is a property of the global object. Resolving as INVALID.
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → INVALID
Marking Verified - Yang Liu, thank you for this report -
Status: RESOLVED → VERIFIED
Targeting as resolved against 1.5R3
Target Milestone: --- → 1.5R3
You need to log in before you can comment on or make changes to this bug.