Skip to content

Commit e6d8ca6

Browse files
committed
add test to guard the feature is not available by default, or with the flag set to false
1 parent af02190 commit e6d8ca6

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/NewSetMethodsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ private static Context getNewSetMethodsContext() {
6161
return JSTest.newContextBuilder().option(JSContextOptions.NEW_SET_METHODS_NAME, "true").build();
6262
}
6363

64+
@Test
65+
public void testNotAvailableByDefault() {
66+
String code = String.format("var set1 = %s; set1.union(set1)", createSetString(1, 2, 3, 4));
67+
68+
try (Context context = JSTest.newContextBuilder().build()) {
69+
context.eval(JavaScriptLanguage.ID, code);
70+
Assert.fail("Should fail with default flags.");
71+
} catch (PolyglotException ex) {
72+
assertTrue(ex.getMessage().contains("union is not a function"));
73+
}
74+
75+
try (Context context = JSTest.newContextBuilder().option(JSContextOptions.NEW_SET_METHODS_NAME, "false").build()) {
76+
context.eval(JavaScriptLanguage.ID, code);
77+
Assert.fail("Should fail with js.new-set-methods=false");
78+
} catch (PolyglotException ex) {
79+
assertTrue(ex.getMessage().contains("union is not a function"));
80+
}
81+
}
82+
6483
@Test
6584
public void testUnion() {
6685
try (Context context = getNewSetMethodsContext()) {

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/SetPrototypeBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ protected JSSetNewOperation(JSContext context, JSBuiltin builtin) {
321321
}
322322

323323
protected Object addEntryFromIterable(Object target, Object iterable, Object adder) {
324-
if (!JSRuntime.isCallable(adder)) {
324+
if (!isCallable(adder)) {
325325
adderError.enter();
326326
throw Errors.createTypeErrorCallableExpected();
327327
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/JSContextOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import com.oracle.truffle.api.Option;
6464
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
6565
import com.oracle.truffle.api.utilities.CyclicAssumption;
66-
import com.oracle.truffle.js.runtime.JSContextOptions.UnhandledRejectionsTrackingMode;
6766

6867
public final class JSContextOptions {
6968

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/JSSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0

0 commit comments

Comments
 (0)