Skip to content

Commit 9d5d8a9

Browse files
committed
scope handling (wip)
1 parent a4f6282 commit 9d5d8a9

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

src/main/java/org/htmlunit/javascript/host/event/EventHandler.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.htmlunit.corejs.javascript.Function;
2020
import org.htmlunit.corejs.javascript.JavaScriptException;
2121
import org.htmlunit.corejs.javascript.Scriptable;
22-
import org.htmlunit.corejs.javascript.ScriptableObject;
23-
import org.htmlunit.corejs.javascript.TopLevel;
2422
import org.htmlunit.html.DomNode;
2523

2624
/**
@@ -65,10 +63,9 @@ public Object call(final Context cx, final Scriptable scope,
6563
// compile "just in time"
6664
if (realFunction_ == null) {
6765
final String js = "function on" + eventName_ + "(event) { " + jsSnippet_ + " \n}";
68-
final TopLevel topLevelScope = ((ScriptableObject) thisObj).getTopLevelScope(thisObj);
69-
realFunction_ = cx.compileFunction(topLevelScope, js, eventName_ + " event for " + node_
66+
realFunction_ = cx.compileFunction(scope, js, eventName_ + " event for " + node_
7067
+ " in " + node_.getPage().getUrl(), 0, null);
71-
realFunction_.setParentScope(topLevelScope);
68+
realFunction_.setParentScope(scope);
7269
}
7370

7471
return realFunction_.call(cx, scope, thisObj, args);

src/main/java/org/htmlunit/javascript/host/worker/DedicatedWorkerGlobalScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void executeEvent(final Context cx, final MessageEvent event) {
305305
final Function handlerFunction = getEventHandler(Event.TYPE_MESSAGE);
306306
if (handlerFunction != null) {
307307
final Object[] args = {event};
308-
handlerFunction.call(cx, this, this, args);
308+
handlerFunction.call(cx, getParentScope(), this, args);
309309
}
310310
}
311311

0 commit comments

Comments
 (0)