Skip to content

Commit 7ac862c

Browse files
committed
scope handling fix (wip)
1 parent 1a06986 commit 7ac862c

5 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/main/java/org/htmlunit/javascript/JavaScriptEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ else if (wow instanceof WorkerGlobalScope w) {
13191319
* @param args the args
13201320
* @return the new object
13211321
*/
1322-
public static Scriptable newObject(final Scriptable scope, final String constructorName, final Object[] args) {
1322+
public static Scriptable newObject(final VarScope scope, final String constructorName, final Object[] args) {
13231323
return ScriptRuntime.newObject(Context.getCurrentContext(), scope, constructorName, args);
13241324
}
13251325

@@ -1331,7 +1331,7 @@ public static Scriptable newObject(final Scriptable scope, final String construc
13311331
* @param scope the scope to search for the constructor and to evaluate against
13321332
* @return the new object
13331333
*/
1334-
public static Scriptable newObject(final Scriptable scope) {
1334+
public static Scriptable newObject(final VarScope scope) {
13351335
final NativeObject result = new NativeObject();
13361336
ScriptRuntime.setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Object);
13371337
return result;

src/main/java/org/htmlunit/javascript/host/Netscape.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package org.htmlunit.javascript.host;
1616

17+
import org.htmlunit.corejs.javascript.VarScope;
1718
import org.htmlunit.javascript.HtmlUnitScriptable;
1819
import org.htmlunit.javascript.JavaScriptEngine;
1920

@@ -25,12 +26,12 @@
2526
*/
2627
public class Netscape extends HtmlUnitScriptable {
2728

28-
Netscape(final Window window) {
29+
Netscape(final VarScope scope) {
2930
super();
30-
setParentScope(window.getWebWindow().getTopLevelScope());
31+
setParentScope(scope);
3132

3233
// simply put "new Object()" for property "security"
33-
put("security", this, JavaScriptEngine.newObject(window));
34+
put("security", this, JavaScriptEngine.newObject(scope));
3435
}
3536

3637
@Override

src/main/java/org/htmlunit/javascript/host/Window.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ public int getScrollY() {
18871887
*/
18881888
@JsxGetter({FF, FF_ESR})
18891889
public Netscape getNetscape() {
1890-
return new Netscape(this);
1890+
return new Netscape(getParentScope());
18911891
}
18921892

18931893
/**

src/main/java/org/htmlunit/javascript/host/svg/SVGMatrix.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
package org.htmlunit.javascript.host.svg;
1616

17-
import org.htmlunit.corejs.javascript.TopLevel;
17+
import org.htmlunit.corejs.javascript.VarScope;
1818
import org.htmlunit.javascript.HtmlUnitScriptable;
1919
import org.htmlunit.javascript.JavaScriptEngine;
2020
import org.htmlunit.javascript.configuration.JsxClass;
@@ -66,7 +66,7 @@ public void jsConstructor() {
6666
* Instantiates and configure scope and prototype.
6767
* @param scope the parent scope
6868
*/
69-
public SVGMatrix(final TopLevel scope) {
69+
public SVGMatrix(final VarScope scope) {
7070
this();
7171
setParentScope(scope);
7272
setPrototype(getPrototype(getClass()));
@@ -186,7 +186,7 @@ public void setF(final double newValue) {
186186
*/
187187
@JsxFunction
188188
public SVGMatrix flipX() {
189-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
189+
final SVGMatrix result = new SVGMatrix(getParentScope());
190190
result.shearX_ = shearX_;
191191
result.shearY_ = -shearY_;
192192
result.scaleX_ = -scaleX_;
@@ -203,7 +203,7 @@ public SVGMatrix flipX() {
203203
*/
204204
@JsxFunction
205205
public SVGMatrix flipY() {
206-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
206+
final SVGMatrix result = new SVGMatrix(getParentScope());
207207
result.shearX_ = -shearX_;
208208
result.shearY_ = shearY_;
209209
result.scaleX_ = scaleX_;
@@ -229,7 +229,7 @@ public SVGMatrix inverse() {
229229
DOMException.INVALID_STATE_ERR);
230230
}
231231

232-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
232+
final SVGMatrix result = new SVGMatrix(getParentScope());
233233
result.shearX_ = -shearX_ / determinant;
234234
result.shearY_ = -shearY_ / determinant;
235235
result.scaleX_ = scaleY_ / determinant;
@@ -247,7 +247,7 @@ public SVGMatrix inverse() {
247247
*/
248248
@JsxFunction
249249
public SVGMatrix multiply(final SVGMatrix by) {
250-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
250+
final SVGMatrix result = new SVGMatrix(getParentScope());
251251

252252
result.shearX_ = by.shearX_ * scaleX_ + by.scaleY_ * shearX_;
253253
result.shearY_ = by.scaleX_ * shearY_ + by.shearY_ * scaleY_;
@@ -270,7 +270,7 @@ public SVGMatrix rotate(final double angle) {
270270
final double sin = Math.sin(theta);
271271
final double cos = Math.cos(theta);
272272

273-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
273+
final SVGMatrix result = new SVGMatrix(getParentScope());
274274

275275
result.shearX_ = -sin * scaleX_ + cos * shearX_;
276276
result.shearY_ = cos * shearY_ + sin * scaleY_;
@@ -301,7 +301,7 @@ public SVGMatrix rotateFromVector(final double x, final double y) {
301301
final double sin = Math.sin(theta);
302302
final double cos = Math.cos(theta);
303303

304-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
304+
final SVGMatrix result = new SVGMatrix(getParentScope());
305305

306306
result.shearX_ = -sin * scaleX_ + cos * shearX_;
307307
result.shearY_ = cos * shearY_ + sin * scaleY_;
@@ -331,7 +331,7 @@ public SVGMatrix scale(final double factor) {
331331
*/
332332
@JsxFunction
333333
public SVGMatrix scaleNonUniform(final double factorX, final double factorY) {
334-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
334+
final SVGMatrix result = new SVGMatrix(getParentScope());
335335

336336
result.shearX_ = factorY * shearX_;
337337
result.shearY_ = factorX * shearY_;
@@ -352,7 +352,7 @@ public SVGMatrix scaleNonUniform(final double factorX, final double factorY) {
352352
public SVGMatrix skewX(final double angle) {
353353
final double shear = Math.tan(Math.toRadians(angle));
354354

355-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
355+
final SVGMatrix result = new SVGMatrix(getParentScope());
356356

357357
result.shearX_ = shear * scaleX_ + shearX_;
358358
result.shearY_ = shearY_;
@@ -373,7 +373,7 @@ public SVGMatrix skewX(final double angle) {
373373
public SVGMatrix skewY(final double angle) {
374374
final double shear = Math.tan(Math.toRadians(angle));
375375

376-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
376+
final SVGMatrix result = new SVGMatrix(getParentScope());
377377

378378
result.shearX_ = shearX_;
379379
result.shearY_ = shearY_ + shear * scaleY_;
@@ -393,7 +393,7 @@ public SVGMatrix skewY(final double angle) {
393393
*/
394394
@JsxFunction
395395
public SVGMatrix translate(final double x, final double y) {
396-
final SVGMatrix result = new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
396+
final SVGMatrix result = new SVGMatrix(getParentScope());
397397

398398
result.shearX_ = shearX_;
399399
result.shearY_ = shearY_;

src/main/java/org/htmlunit/javascript/host/svg/SVGSVGElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void jsConstructor() {
5454
*/
5555
@JsxFunction
5656
public SVGMatrix createSVGMatrix() {
57-
return new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
57+
return new SVGMatrix(getParentScope());
5858
}
5959

6060
/**
@@ -63,7 +63,7 @@ public SVGMatrix createSVGMatrix() {
6363
*/
6464
@JsxFunction
6565
public SVGMatrix getScreenCTM() {
66-
return new SVGMatrix(getWindow().getWebWindow().getTopLevelScope());
66+
return new SVGMatrix(getParentScope());
6767
}
6868

6969
/**

0 commit comments

Comments
 (0)