Closed Bug 23743 Opened 25 years ago Closed 25 years ago

JS_CallFunctionName seems to be broken

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Windows NT
defect

Tracking

()

VERIFIED WONTFIX

People

(Reporter: clayton, Assigned: brendan)

Details

(Keywords: js1.5)

Attachments

(2 files)

While testing the JS 1.5 pre (JS_15b1_991216_BRANCH) I recognized that
JS_CallFunctionName seems to be broken.

Could this be a side effect of the new function treatment? (auto-cloning)

Compiling a simple script

function a()
{}

and trying to execute it with JS_CallFunctionName() results in returning
"false".

This is done with one single global object without prototype chain. (So this is
the trivial case)

Till Vollmer, Technical Product Manager
Hyperwave Software R & D, Albrechtgasse 9/2, A-8010 Graz, Austria
Tel. +43 316 82 09 18-39, Fax +43 316 82 09 18-99
mailto:tvollmer@hyperwave.com
http://www.hyperwave.com
Assignee: mccabe → rogerl
Passing this one on to Roger.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
I can't reproduce the problem here.  Attaching a testcase which *does not* show
the problem, and marking invalid.

Feel free to re-open if you can reporduce the bug.
Attached file testcase (main.c)
Testcase produces the following output on my system:

(gdb) run
Starting program: /home/rginda/src/tests/js_callfunc/main
1
undefined
Status: RESOLVED → REOPENED
Sorry for the to unspecific problem report:
The problem only arises if you ONLY JS_CompileScript() and than directly call
JS_CallFunctionName() without evaluating or executing it first. This was working
prior to the 1.5 engine. (Consider a script that has only one function in it)

The reason is simple:
Because of the new auto-cloning functions are not really defined as
Properties on compile time, they are only atoms. On execution
(opcode:JSOP_DEFFUN in jsinterp.c) they will be defined as real
properties.

But JS_CallFunctionName uses JS_GetProperty to find the function, which
is not working anymore, when you do not evaluate it first.

I am not sure if this is a bug or just a change of behaviour. Calling
JS_Evaluate() after compiling and than again calling JS_CallFunctionName would
execute the script twice: First to only define the function property and than to
really execute the function.
Resolution: INVALID → ---
Clearing INVALID resolution due to reopen.
Keywords: js1.5
Assignee: rogerl → brendan
Status: REOPENED → NEW
Why don't I just take this, since I perpetrated JSOP_DEFFUN (for good reason).

/be
Status: NEW → ASSIGNED
Target Milestone: M13
Thanks Brendan.  Happy to have you looking at it.  Roger has a backlog of stuff
on his plate right now, too.   = C =
Status: ASSIGNED → RESOLVED
Closed: 25 years ago25 years ago
Resolution: --- → WONTFIX
Till, this is a change of behavior as you say, and an API incompatibility, but I
don't see how to avoid it and keep both ECMA compliance, and brutal sharing (an
important Mozilla optimization) working.

You write "Calling JS_Evaluate() after compiling and than again calling
JS_CallFunctionName would execute the script twice", but I wanted to set your
mind at ease: the script needs to be executed once only (by JS_ExecuteScript,
not JS_EvaluateScript or one of its variants), but that execution does *not*
execute the function.  You execute a function's code by invoking it, not by
evaluating its declaring statement or expression.

With XUL brutal sharing in Mozilla, we have a similar issue: we compile event
handlers once but must bind clones of each handler function to many target
objects in different windows.  So we have to call JS API entry points beyond
JS_Compile*, particularly JS_CloneFunctionObject and JS_DefineProperty.

Please mail me or post to the .jseng newsgroup if you find this API change to be
a great hardship, and cannot use JS_ExecuteScript after compiling, or (simpler)
just JS_Evaluate*Script (which is short for compile + execute).

/be
Marking Verified.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: