Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 14, 2024
1 parent 5a0c379 commit 3d0ca01
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.mozilla.javascript.tests.es5;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.tests.Utils;

/**
Expand All @@ -14,21 +11,23 @@ public class StrictTest {

@Test
public void functionCtor() {
final String script = "(function() {"
+ "'use strict';"
+ "Function('with(this) { }')();"
+ "})();"
+ "'done'";
final String script =
"(function() {"
+ "'use strict';"
+ "Function('with(this) { }')();"
+ "})();"
+ "'done'";
Utils.assertWithAllOptimizationLevels("done", script);
}

@Test
public void newFunction() {
final String script = "(function() {"
+ "'use strict';"
+ "new Function('with(this) { }')();"
+ "})();" +
"'done'";
final String script =
"(function() {"
+ "'use strict';"
+ "new Function('with(this) { }')();"
+ "})();"
+ "'done'";
Utils.assertWithAllOptimizationLevels("done", script);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

import static org.junit.Assert.assertEquals;

import org.junit.Assert;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.EvaluatorException;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.tests.Utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,160 +7,168 @@
*/
package org.mozilla.javascript.tests.es6;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.tests.Utils;

public class ObjectSealFreezeTest {

@Test
public void sealWriteToExistingWritableProperty() {
final String script = "foo = function() {"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.seal(r);"
+ " r.a = 'Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.seal(r);"
+ " r.a = 'Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Rhino", script);
}

@Test
public void sealWriteToExistingWritablePropertyStrict() {
final String script = "foo = function() {"
+ " 'use strict';"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.seal(r);"
+ " r.a='Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " 'use strict';"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.seal(r);"
+ " r.a='Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Rhino", script);
}

@Test
public void sealWriteToExistingSymbolProperty() {
final String script = "foo = function() {"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.seal(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.seal(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Rhino", script);
}

@Test
public void sealWriteToExistingSymbolPropertyStrict() {
final String script = "foo = function() {"
+ " 'use strict';"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.seal(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " 'use strict';"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.seal(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Rhino", script);
}

@Test
public void freezeWriteToExistingWritableProperty() {
final String script = "foo = function() {"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.freeze(r);"
+ " r.a = 'Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.freeze(r);"
+ " r.a = 'Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("abc", script);
}

@Test
public void freezeWriteToExistingWritablePropertyStrict() {
final String script = "foo = function() {"
+ " 'use strict';"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.freeze(r);"
+ " r.a='Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Cannot add properties to this object because extensible is false.", script);
final String script =
"foo = function() {"
+ " 'use strict';"
+ " var r = {};"
+ " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });"
+ " Object.freeze(r);"
+ " r.a='Rhino';"
+ " return r.a;"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6(
"Cannot add properties to this object because extensible is false.", script);
}

@Test
public void freezeWriteToExistingSymbolProperty() {
final String script = "foo = function() {"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.freeze(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
final String script =
"foo = function() {"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.freeze(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("abc", script);
}

@Test
public void freezeWriteToExistingSymbolPropertyStrict() {
final String script = "foo = function() {"
+ " 'use strict';"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.freeze(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6("Cannot add properties to this object because extensible is false.", script);
final String script =
"foo = function() {"
+ " 'use strict';"
+ " var sym = Symbol('X');"
+ " var r = {};"
+ " r[sym] = 'abc';"
+ " Object.freeze(r);"
+ " r[sym] = 'Rhino';"
+ " return r[sym];"
+ "};"
+ "try { "
+ " foo();"
+ "} catch (e) { e.message }";
Utils.assertWithAllOptimizationLevelsES6(
"Cannot add properties to this object because extensible is false.", script);
}

@Test
public void objectConstructorForNonExtensibleFunctions() {
final String script = "foo = function() {"
+ " var res = '';\n"
+ " var a = JSON.stringify;\n"
+ " Object.preventExtensions(a);\n"
+ " res += 'a.isExtensible = ' + Object.isExtensible(a);\n"
+ " res += '\\n';\n"
+ " var b = Object(a);\n"
+ " res += typeof b;\n"
+ " res += '\\n';\n"
+ " res += a===b;\n"
+ " res += '\\n';\n"
+ " res += 'b.isExtensible = ' + Object.isExtensible(b);\n"
+ " return res;\n"
+ "};"
+ " foo();";
Utils.assertWithAllOptimizationLevelsES6("a.isExtensible = false\nfunction\ntrue\nb.isExtensible = false", script);
final String script =
"foo = function() {"
+ " var res = '';\n"
+ " var a = JSON.stringify;\n"
+ " Object.preventExtensions(a);\n"
+ " res += 'a.isExtensible = ' + Object.isExtensible(a);\n"
+ " res += '\\n';\n"
+ " var b = Object(a);\n"
+ " res += typeof b;\n"
+ " res += '\\n';\n"
+ " res += a===b;\n"
+ " res += '\\n';\n"
+ " res += 'b.isExtensible = ' + Object.isExtensible(b);\n"
+ " return res;\n"
+ "};"
+ " foo();";
Utils.assertWithAllOptimizationLevelsES6(
"a.isExtensible = false\nfunction\ntrue\nb.isExtensible = false", script);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,33 @@
*/
package org.mozilla.javascript.tests.es6;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.TopLevel;
import org.mozilla.javascript.tests.Utils;

public class PromiseTest {

@Test
public void ctorCallableThis() {
final String script = " var r = '';"
+ " var p = new Promise(function(resolve, reject) {\n"
+ " r += this;\n"
+ " });\n"
+ " r += ' done';\n"
+ " r;";
final String script =
" var r = '';"
+ " var p = new Promise(function(resolve, reject) {\n"
+ " r += this;\n"
+ " });\n"
+ " r += ' done';\n"
+ " r;";
Utils.assertWithAllOptimizationLevelsTopLevelScopeES6("[object global] done", script);
}

@Test
public void ctorCallableThisStrict() {
final String script = "'use strict';"
+ " var r = '';"
+ " var p = new Promise(function(resolve, reject) {\n"
+ " r += this === undefined;\n"
+ " });\n"
+ " r += ' done';\n"
+ " r;";
final String script =
"'use strict';"
+ " var r = '';"
+ " var p = new Promise(function(resolve, reject) {\n"
+ " r += this === undefined;\n"
+ " });\n"
+ " r += ' done';\n"
+ " r;";
Utils.assertWithAllOptimizationLevelsES6("true done", script);
}
}

0 comments on commit 3d0ca01

Please sign in to comment.