Skip to content

Commit 28b4744

Browse files
committed
use initSafeStandardObjects
1 parent cf23a5d commit 28b4744

25 files changed

+86
-86
lines changed

src/test/java/net/sourceforge/htmlunit/ArgumentsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected boolean hasFeature(final Context cx, final int featureIndex) {
136136
final ContextAction action = new ContextAction() {
137137
@Override
138138
public Object run(final Context cx) {
139-
final Scriptable scope = cx.initStandardObjects();
139+
final Scriptable scope = cx.initSafeStandardObjects();
140140
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
141141
assertEquals(expectedResult, result);
142142
return null;
@@ -177,7 +177,7 @@ private static void test(final String script, final Object expected) {
177177
@Override
178178
public Object run(final Context cx) {
179179
try {
180-
Scriptable scope = cx.initStandardObjects();
180+
Scriptable scope = cx.initSafeStandardObjects();
181181
final Object o = cx.evaluateString(scope, script, "test_script", 1, null);
182182
assertEquals(expected, o);
183183
return o;

src/test/java/net/sourceforge/htmlunit/ContextMethodsTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
1818

1919
/**
20-
* Unit tests for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=481152">Bug 481152 -
21-
* Open Context class for extension</a>
20+
* Unit tests for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=481152">Bug 481152 -
21+
* Open Context class for extension</a>
2222
* @author Marc Guillemot
2323
*/
2424
public class ContextMethodsTest {
25-
25+
2626
/**
2727
* When {@link Context#compileString(String, String, int, Object)} is protected and not final,
2828
* we can capture code passed to eval.
@@ -47,19 +47,19 @@ protected Script compileString(String source, Evaluator compiler,
4747
};
4848
}
4949
};
50-
50+
5151
final String source = "eval('1 + 2')";
52-
52+
5353
final ContextAction action = new ContextAction() {
5454
@Override
5555
public Object run(Context cx) {
56-
final Scriptable scope = cx.initStandardObjects();
56+
final Scriptable scope = cx.initSafeStandardObjects();
5757
final Script script = cx.compileString(source, "", 1, (Object) null);
5858
return script.exec(cx, scope);
5959
};
6060
};
6161
cf.call(action);
62-
62+
6363
final String[] expected = { "eval('1 + 2')", "1 + 2" };
6464
assertEquals(Arrays.asList(expected), compiled);
6565
}

src/test/java/net/sourceforge/htmlunit/DelegatorAndHostObjectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Unit tests for <a
1515
* href="https://bugzilla.mozilla.org/show_bug.cgi?id=539875">Bug 539875 -
1616
* Delegator incompatible with host objects with functions</a>.
17-
*
17+
*
1818
* @author Daniel Gredler
1919
* @author Marc Guillemot
2020
* @author Ahmed Ashour
@@ -88,7 +88,7 @@ private static void test(final String script, final Object expected) {
8888
@Override
8989
public Object run(final Context cx) {
9090
try {
91-
Scriptable scope = cx.initStandardObjects();
91+
Scriptable scope = cx.initSafeStandardObjects();
9292
ScriptableObject.defineClass(scope, MyHostObject.class);
9393
final Object o = cx.evaluateString(scope, script, "test_script", 1, null);
9494
assertEquals(expected, o);

src/test/java/net/sourceforge/htmlunit/EvalScopeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public Object run(final Context cx) {
6161

6262
final MyHostObject host1 = new MyHostObject(1);
6363
host1.setPrototype(prototype);
64-
cx.initStandardObjects(host1);
64+
cx.initSafeStandardObjects(host1);
6565

6666
final MyHostObject host2 = new MyHostObject(2);
6767
host2.setPrototype(prototype);
68-
cx.initStandardObjects(host2);
68+
cx.initSafeStandardObjects(host2);
6969

7070
ScriptableObject.defineProperty(host1, "host1", host1, ScriptableObject.EMPTY);
7171
ScriptableObject.defineProperty(host1, "host2", host2, ScriptableObject.EMPTY);

src/test/java/net/sourceforge/htmlunit/ExceptionMessageTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static void exceptionMessage(final String script, final String expectedM
4343
@Override
4444
public Object run(final Context cx) {
4545
try {
46-
Scriptable scope = cx.initStandardObjects();
46+
Scriptable scope = cx.initSafeStandardObjects();
4747

4848
cx.evaluateString(scope, script, "test_script", 1, null);
4949
throw new RuntimeException("Should have failed!");
@@ -80,14 +80,14 @@ protected boolean hasFeature(Context cx, int featureIndex) {
8080
return super.hasFeature(cx, featureIndex);
8181
}
8282
};
83-
83+
8484
final String script = "o.readonlyProp = 123";
85-
85+
8686
final ContextAction action = new ContextAction() {
8787
@Override
8888
public Object run(final Context cx) {
8989
try {
90-
Scriptable scope = cx.initStandardObjects();
90+
Scriptable scope = cx.initSafeStandardObjects();
9191
final MyHostObject prototype = new MyHostObject();
9292
ScriptableObject.defineClass(scope, MyHostObject.class);
9393
final Method readMethod = MyHostObject.class.getMethod("jsxGet_x");

src/test/java/net/sourceforge/htmlunit/ExceptionPropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Object run(final Context cx) {
7373
cx.setLanguageVersion(Context.VERSION_ES6);
7474

7575
try {
76-
final ScriptableObject scope = cx.initStandardObjects();
76+
final ScriptableObject scope = cx.initSafeStandardObjects();
7777
final Object o = cx.evaluateString(scope, script,
7878
"myScript.js", 1, null);
7979
assertEquals(expected, o);

src/test/java/net/sourceforge/htmlunit/FunctionCallerTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void upperScopeVarShouldntBeSetWithVarFunctionWithSameName() throws Excep
2929
final ContextAction action = new ContextAction() {
3030
@Override
3131
public Object run(final Context cx) {
32-
final Scriptable scope = cx.initStandardObjects();
32+
final Scriptable scope = cx.initSafeStandardObjects();
3333
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
3434
assertEquals(Boolean.TRUE, result);
3535
return null;
@@ -56,7 +56,7 @@ public void notEnumerated() throws Exception {
5656
final ContextAction action = new ContextAction() {
5757
@Override
5858
public Object run(final Context cx) {
59-
final Scriptable scope = cx.initStandardObjects();
59+
final Scriptable scope = cx.initSafeStandardObjects();
6060
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
6161
assertEquals("", result);
6262
return null;
@@ -83,12 +83,12 @@ public void callee() throws Exception {
8383
+ " if (c != f) throw 'got: ' + c;\n"
8484
+ "}\n"
8585
+ "f();\n";
86-
86+
8787
final ContextAction action = new ContextAction() {
8888
@Override
8989
public Object run(final Context cx) {
90-
final Scriptable scope = cx.initStandardObjects();
91-
90+
final Scriptable scope = cx.initSafeStandardObjects();
91+
9292
cx.evaluateString(scope, script, "test.js", 1, null);
9393

9494
return null;
@@ -116,12 +116,12 @@ public void callerArguments() throws Exception {
116116
+ "var output = '';\n"
117117
+ "f();\n"
118118
+ "output";
119-
119+
120120
final ContextAction action = new ContextAction() {
121121
@Override
122122
public Object run(final Context cx) {
123-
final Scriptable scope = cx.initStandardObjects();
124-
123+
final Scriptable scope = cx.initSafeStandardObjects();
124+
125125
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
126126
assertEquals("2-2", result);
127127
return null;
@@ -154,8 +154,8 @@ public void arguments() throws Exception {
154154
final ContextAction action = new ContextAction() {
155155
@Override
156156
public Object run(final Context cx) {
157-
final Scriptable scope = cx.initStandardObjects();
158-
157+
final Scriptable scope = cx.initSafeStandardObjects();
158+
159159
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
160160
assertEquals("2-hello-2", result);
161161
return null;
@@ -180,12 +180,12 @@ public void callerArgumentsCallee() throws Exception {
180180
+ "var output = '';\n"
181181
+ "g();\n"
182182
+ "output";
183-
183+
184184
final ContextAction action = new ContextAction() {
185185
@Override
186186
public Object run(final Context cx) {
187-
final Scriptable scope = cx.initStandardObjects();
188-
187+
final Scriptable scope = cx.initSafeStandardObjects();
188+
189189
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
190190
assertEquals("true, true", result);
191191
return null;

src/test/java/net/sourceforge/htmlunit/FunctionNullSetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void setFunctionToNull() throws Exception {
2929
@Override
3030
public Object run(final Context cx) {
3131
try {
32-
final Scriptable scope = cx.initStandardObjects();
32+
final Scriptable scope = cx.initSafeStandardObjects();
3333
final MyHostObject prototype = new MyHostObject();
3434
ScriptableObject.defineClass(scope, MyHostObject.class);
3535
final Method getterMethod = MyHostObject.class.getMethod("jsxGet_onclick");

src/test/java/net/sourceforge/htmlunit/FunctionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
* @author Ahmed Ashour
1717
*/
1818
public class FunctionTest {
19-
19+
2020
/**
2121
* Test for bug #600479
2222
* https://bugzilla.mozilla.org/show_bug.cgi?id=600479
2323
* Syntax of function built from Function's constructor string parameter was not correct
24-
* when this string contained "//".
24+
* when this string contained "//".
2525
*/
2626
@Test
2727
public void testFunctionWithSlashSlash() {
@@ -32,7 +32,7 @@ private static void assertEvaluates(final Object expected, final String source)
3232
final ContextAction action = new ContextAction() {
3333
@Override
3434
public Object run(Context cx) {
35-
final Scriptable scope = cx.initStandardObjects();
35+
final Scriptable scope = cx.initSafeStandardObjects();
3636
final Object rep = cx.evaluateString(scope, source, "test.js", 0, null);
3737
assertEquals(expected, rep);
3838
return null;

src/test/java/net/sourceforge/htmlunit/HostExceptionsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testCatchJSException() throws Exception {
2727
}
2828

2929
/**
30-
* If configured, JS catch block should not catch Java exception
30+
* If configured, JS catch block should not catch Java exception
3131
*/
3232
@Test
3333
public void testDontCatchJavaException_inGetter() throws Exception {
@@ -41,7 +41,7 @@ public void testDontCatchJavaException_inGetter() throws Exception {
4141
}
4242

4343
/**
44-
* If configured, JS catch block should not catch Java exception
44+
* If configured, JS catch block should not catch Java exception
4545
*/
4646
@Test
4747
public void testDontCatchJavaException_inFunction() throws Exception {
@@ -61,14 +61,14 @@ private static void doTest(final String jsExpression) throws Exception {
6161
final ContextAction action = new ContextAction() {
6262
@Override
6363
public Object run(final Context cx) {
64-
final Scriptable scope = cx.initStandardObjects();
64+
final Scriptable scope = cx.initSafeStandardObjects();
6565
try {
6666
ScriptableObject.defineClass(scope, MyScriptable.class);
6767
}
6868
catch (final Exception e) {
6969
throw new RuntimeException();
7070
}
71-
71+
7272
cx.evaluateString(scope, script, "test.js", 0, null);
7373

7474
return null;
@@ -83,15 +83,15 @@ public static class MyScriptable extends ScriptableObject {
8383
public String getClassName() {
8484
return "MyScriptable";
8585
}
86-
86+
8787
public String jsGet_willThrowJavaException() {
8888
throw javaException;
8989
}
9090

9191
public String jsGet_willThrowJSException() {
9292
throw Context.reportRuntimeError("this is a JS exception");
9393
}
94-
94+
9595
public void jsFunction_throwJavaException() {
9696
throw javaException;
9797
}

0 commit comments

Comments
 (0)