diff --git a/graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestBindings.java b/graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestBindings.java index 65712b291b7..7178751ec6b 100644 --- a/graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestBindings.java +++ b/graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestBindings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -80,6 +80,22 @@ private ScriptEngine getEngine() { return manager.getEngineByName(TestEngine.TESTED_ENGINE_NAME); } + @Test + public void engineEmptyBindings() { + ScriptEngine engine = getEngine(); + Bindings bindings = engine.createBindings(); + engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE); + assertEquals(bindings, engine.getBindings(ScriptContext.ENGINE_SCOPE)); + } + + @Test + public void globalEmptyBindings() { + ScriptEngine engine = getEngine(); + Bindings bindings = engine.createBindings(); + engine.setBindings(bindings, ScriptContext.GLOBAL_SCOPE); + assertEquals(bindings, engine.getBindings(ScriptContext.GLOBAL_SCOPE)); + } + @Test public void enginePut() throws ScriptException { ScriptEngine engine = getEngine(); diff --git a/graal-js/src/com.oracle.truffle.js.scriptengine/src/com/oracle/truffle/js/scriptengine/GraalJSBindings.java b/graal-js/src/com.oracle.truffle.js.scriptengine/src/com/oracle/truffle/js/scriptengine/GraalJSBindings.java index 4b9588d365e..1a78bb27360 100644 --- a/graal-js/src/com.oracle.truffle.js.scriptengine/src/com/oracle/truffle/js/scriptengine/GraalJSBindings.java +++ b/graal-js/src/com.oracle.truffle.js.scriptengine/src/com/oracle/truffle/js/scriptengine/GraalJSBindings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -219,7 +219,11 @@ void importGlobalBindings(ScriptContext scriptContext) { void updateEngineScriptContext(ScriptContext scriptContext) { engineScriptContext = scriptContext; - updateContextBinding(); + if (context != null) { + updateContextBinding(); + } else { + initContext(); // This will also call updateContextBinding() + } } }