From e2a8a382cc4d572366e06540be828adc04adbe61 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:33:33 +0300 Subject: [PATCH] refactoring --- .../jscript/common/Instruction.java | 1 - .../SyntaxException.java | 2 +- .../topchetoeu/jscript/common/json/JSON.java | 2 +- .../jscript/common/parsing/Parsing.java | 2 +- .../jscript/compilation/JavaScript.java | 2 +- .../jscript/compilation/LabelContext.java | 2 +- .../compilation/control/BreakNode.java | 2 +- .../compilation/control/ContinueNode.java | 2 +- .../compilation/patterns/AssignPattern.java | 2 +- .../compilation/patterns/ObjectPattern.java | 2 +- .../jscript/compilation/scope/Scope.java | 2 +- .../compilation/values/ObjectNode.java | 2 +- .../compilation/values/VariableNode.java | 2 +- .../values/operations/AssignNode.java | 2 +- .../topchetoeu/jscript/runtime/Compiler.java | 2 +- .../jscript/runtime/SimpleRepl.java | 2 +- .../jscript/runtime/debug/DebugContext.java | 33 +------------------ .../jscript/runtime/debug/DebugHandler.java | 21 ------------ .../jscript/runtime/values/KeyCache.java | 2 ++ .../jscript/runtime/values/Value.java | 6 ++-- .../runtime/values/objects/ObjectValue.java | 5 +-- 21 files changed, 24 insertions(+), 74 deletions(-) rename src/main/java/me/topchetoeu/jscript/{runtime/exceptions => common}/SyntaxException.java (87%) diff --git a/src/main/java/me/topchetoeu/jscript/common/Instruction.java b/src/main/java/me/topchetoeu/jscript/common/Instruction.java index f7d38ad..2956c7c 100644 --- a/src/main/java/me/topchetoeu/jscript/common/Instruction.java +++ b/src/main/java/me/topchetoeu/jscript/common/Instruction.java @@ -5,7 +5,6 @@ import java.util.function.IntFunction; import java.util.function.IntSupplier; import me.topchetoeu.jscript.common.parsing.Location; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class Instruction { public static enum Type { diff --git a/src/main/java/me/topchetoeu/jscript/runtime/exceptions/SyntaxException.java b/src/main/java/me/topchetoeu/jscript/common/SyntaxException.java similarity index 87% rename from src/main/java/me/topchetoeu/jscript/runtime/exceptions/SyntaxException.java rename to src/main/java/me/topchetoeu/jscript/common/SyntaxException.java index 023df78..2483e6f 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/exceptions/SyntaxException.java +++ b/src/main/java/me/topchetoeu/jscript/common/SyntaxException.java @@ -1,4 +1,4 @@ -package me.topchetoeu.jscript.runtime.exceptions; +package me.topchetoeu.jscript.common; import me.topchetoeu.jscript.common.parsing.Location; diff --git a/src/main/java/me/topchetoeu/jscript/common/json/JSON.java b/src/main/java/me/topchetoeu/jscript/common/json/JSON.java index 49aeb29..56c34c9 100644 --- a/src/main/java/me/topchetoeu/jscript/common/json/JSON.java +++ b/src/main/java/me/topchetoeu/jscript/common/json/JSON.java @@ -4,11 +4,11 @@ import java.math.BigDecimal; import java.util.HashMap; import java.util.stream.Collectors; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Filename; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; import me.topchetoeu.jscript.common.parsing.Source; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class JSON { public static ParseRes parseString(Source src, int i) { diff --git a/src/main/java/me/topchetoeu/jscript/common/parsing/Parsing.java b/src/main/java/me/topchetoeu/jscript/common/parsing/Parsing.java index 925c3d3..fb5acc6 100644 --- a/src/main/java/me/topchetoeu/jscript/common/parsing/Parsing.java +++ b/src/main/java/me/topchetoeu/jscript/common/parsing/Parsing.java @@ -1,7 +1,7 @@ package me.topchetoeu.jscript.common.parsing; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.compilation.values.constants.NumberNode; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class Parsing { public static boolean isDigit(Character c) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java b/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java index 620c3db..f11542b 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.parsing.Filename; import me.topchetoeu.jscript.common.parsing.ParseRes; @@ -42,7 +43,6 @@ import me.topchetoeu.jscript.compilation.values.operations.IndexNode; import me.topchetoeu.jscript.compilation.values.operations.OperationNode; import me.topchetoeu.jscript.compilation.values.operations.PostfixNode; import me.topchetoeu.jscript.compilation.values.operations.TypeofNode; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public final class JavaScript { public static enum DeclarationType { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/LabelContext.java b/src/main/java/me/topchetoeu/jscript/compilation/LabelContext.java index 0dea994..22f371c 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/LabelContext.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/LabelContext.java @@ -6,10 +6,10 @@ import java.util.function.IntFunction; import java.util.function.IntSupplier; import me.topchetoeu.jscript.common.Instruction; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Key; import me.topchetoeu.jscript.common.parsing.Location; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class LabelContext { public static final Key BREAK_CTX = Key.of(); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java index b09b8ca..ee2c7aa 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.compilation.control; import me.topchetoeu.jscript.common.Instruction; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; @@ -9,7 +10,6 @@ import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.compilation.LabelContext; import me.topchetoeu.jscript.compilation.Node; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class BreakNode extends Node { public final String label; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java index da7eebb..2b8a677 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.compilation.control; import me.topchetoeu.jscript.common.Instruction; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; @@ -9,7 +10,6 @@ import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.compilation.LabelContext; import me.topchetoeu.jscript.compilation.Node; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class ContinueNode extends Node { public final String label; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/patterns/AssignPattern.java b/src/main/java/me/topchetoeu/jscript/compilation/patterns/AssignPattern.java index f7fa3b8..60bd776 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/patterns/AssignPattern.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/patterns/AssignPattern.java @@ -2,6 +2,7 @@ package me.topchetoeu.jscript.compilation.patterns; import me.topchetoeu.jscript.common.Instruction; import me.topchetoeu.jscript.common.Operation; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; @@ -10,7 +11,6 @@ import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.compilation.Node; import me.topchetoeu.jscript.compilation.JavaScript.DeclarationType; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class AssignPattern implements Pattern { public final Location loc; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/patterns/ObjectPattern.java b/src/main/java/me/topchetoeu/jscript/compilation/patterns/ObjectPattern.java index cd9e120..ca395fa 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/patterns/ObjectPattern.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/patterns/ObjectPattern.java @@ -3,6 +3,7 @@ package me.topchetoeu.jscript.compilation.patterns; import java.util.LinkedList; import java.util.List; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; @@ -12,7 +13,6 @@ import me.topchetoeu.jscript.compilation.JavaScript.DeclarationType; import me.topchetoeu.jscript.compilation.values.ObjectNode; import me.topchetoeu.jscript.compilation.values.VariableNode; import me.topchetoeu.jscript.compilation.values.constants.StringNode; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class ObjectPattern extends ObjectDestructor implements Pattern { @Override public void destructDeclResolve(CompileResult target) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java b/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java index 3d3006a..e848e40 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java @@ -3,9 +3,9 @@ package me.topchetoeu.jscript.compilation.scope; import java.util.HashMap; import java.util.LinkedList; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.compilation.JavaScript.DeclarationType; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class Scope { protected final HashMap strictVarMap = new HashMap<>(); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java index 3a05ab8..35ddbab 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import java.util.List; import me.topchetoeu.jscript.common.Instruction; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.Instruction.BreakpointType; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; @@ -24,7 +25,6 @@ import me.topchetoeu.jscript.compilation.patterns.ObjectDestructor.Member; import me.topchetoeu.jscript.compilation.values.constants.NumberNode; import me.topchetoeu.jscript.compilation.values.constants.StringNode; import me.topchetoeu.jscript.compilation.values.operations.AssignNode; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class ObjectNode extends Node implements AssignTargetLike { public static class PropertyMemberNode extends FunctionNode { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java index 9c2d3d7..5c519ee 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java @@ -3,6 +3,7 @@ package me.topchetoeu.jscript.compilation.values; import java.util.function.IntFunction; import me.topchetoeu.jscript.common.Instruction; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.common.parsing.ParseRes; import me.topchetoeu.jscript.common.parsing.Parsing; @@ -14,7 +15,6 @@ import me.topchetoeu.jscript.compilation.JavaScript.DeclarationType; import me.topchetoeu.jscript.compilation.patterns.ChangeTarget; import me.topchetoeu.jscript.compilation.patterns.Pattern; import me.topchetoeu.jscript.compilation.scope.Variable; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class VariableNode extends Node implements Pattern, ChangeTarget { public final String name; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/AssignNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/AssignNode.java index bea0b41..20ccbb2 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/AssignNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/AssignNode.java @@ -2,11 +2,11 @@ package me.topchetoeu.jscript.compilation.values.operations; import me.topchetoeu.jscript.common.Instruction; import me.topchetoeu.jscript.common.Operation; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.Node; import me.topchetoeu.jscript.compilation.patterns.AssignTarget; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class AssignNode extends Node implements AssignTarget { public final AssignTarget assignable; diff --git a/src/main/java/me/topchetoeu/jscript/runtime/Compiler.java b/src/main/java/me/topchetoeu/jscript/runtime/Compiler.java index fea091c..526e646 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/Compiler.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/Compiler.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.runtime; import me.topchetoeu.jscript.common.FunctionBody; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Key; import me.topchetoeu.jscript.common.parsing.Filename; @@ -8,7 +9,6 @@ import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.functions.CodeFunction; diff --git a/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java b/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java index 0a6da34..8c4adcd 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/SimpleRepl.java @@ -8,12 +8,12 @@ import java.util.concurrent.ExecutionException; import me.topchetoeu.jscript.common.Metadata; import me.topchetoeu.jscript.common.Reading; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.json.JSON; import me.topchetoeu.jscript.common.parsing.Filename; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; import me.topchetoeu.jscript.runtime.values.Member.FieldMember; import me.topchetoeu.jscript.runtime.values.Member.PropertyMember; import me.topchetoeu.jscript.runtime.values.Value; diff --git a/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java b/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java index b8d6127..e87905c 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java @@ -1,6 +1,5 @@ package me.topchetoeu.jscript.runtime.debug; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -12,7 +11,6 @@ import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Key; import me.topchetoeu.jscript.common.mapping.FunctionMap; import me.topchetoeu.jscript.common.parsing.Filename; -import me.topchetoeu.jscript.common.parsing.Location; import me.topchetoeu.jscript.runtime.Frame; import me.topchetoeu.jscript.runtime.exceptions.EngineException; import me.topchetoeu.jscript.runtime.values.functions.CodeFunction; @@ -49,8 +47,7 @@ public class DebugContext { } public DebugHandler debugger() { - if (debugger == null) return DebugHandler.empty(); - else return debugger; + return debugger; } public FunctionMap getMap(FunctionBody func) { @@ -118,32 +115,4 @@ public class DebugContext { if (enabled(exts)) return exts.get(KEY); else return new DebugContext(false); } - - public static List stackTrace(Environment env) { - var res = new ArrayList(); - var dbgCtx = get(env); - - for (var frame : dbgCtx.getStackFrames()) { - var name = frame.function.name; - - var map = dbgCtx.getMapOrEmpty(frame.function); - Location loc = null; - - if (map != null) { - loc = map.toLocation(frame.codePtr, true); - if (loc == null) loc = map.start(); - } - - var trace = ""; - - if (loc != null) trace += "at " + loc.toString() + " "; - if (name != null && !name.equals("")) trace += "in " + name + " "; - - trace = trace.trim(); - - if (!trace.equals("")) res.add(trace); - } - - return res; - } } diff --git a/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugHandler.java b/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugHandler.java index ea325ca..cd7478a 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugHandler.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/debug/DebugHandler.java @@ -1,6 +1,5 @@ package me.topchetoeu.jscript.runtime.debug; -import java.util.Arrays; import java.util.List; import me.topchetoeu.jscript.common.FunctionBody; @@ -28,13 +27,6 @@ public interface DebugHandler { */ void onFunctionLoad(FunctionBody body, FunctionMap map); - // /** - // * Called when a function body has been loaded - // * @param body The body loaded - // * @param map The map of the function - // */ - // void onFunctionUnload(FunctionBody body, FunctionMap map); - /** * Called immediatly before an instruction is executed, as well as after an instruction, if it has threw or returned. * This function might pause in order to await debugging commands. @@ -64,17 +56,4 @@ public interface DebugHandler { void onFramePop(Environment env, Frame frame); List getStackFrame(); - - public static DebugHandler empty() { - return new DebugHandler () { - @Override public void onFramePop(Environment env, Frame frame) { } - @Override public void onFramePush(Environment env, Frame frame) { } - @Override public boolean onInstruction(Environment env, Frame frame, Instruction instruction, Object returnVal, EngineException error, boolean caught) { - return false; - } - @Override public void onSourceLoad(Filename filename, String source) { } - @Override public void onFunctionLoad(FunctionBody body, FunctionMap map) { } - @Override public List getStackFrame() { return Arrays.asList(); } - }; - } } diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/KeyCache.java b/src/main/java/me/topchetoeu/jscript/runtime/values/KeyCache.java index 88be685..4d70dd5 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/KeyCache.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/KeyCache.java @@ -57,12 +57,14 @@ public final class KeyCache { } public KeyCache(int value) { this.value = NumberValue.of(value); + this.isInt = true; this.intCache = value; this.doubleCache = (double)value; this.booleanCache = value != 0; } public KeyCache(double value) { this.value = NumberValue.of(value); + this.isInt = (int)value == value; this.intCache = (int)value; this.doubleCache = value; this.booleanCache = value != 0; diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java b/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java index 7ad0c4c..0e654b9 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java @@ -11,6 +11,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import me.topchetoeu.jscript.common.SyntaxException; import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Key; import me.topchetoeu.jscript.common.json.JSON; @@ -18,7 +19,6 @@ import me.topchetoeu.jscript.common.json.JSONElement; import me.topchetoeu.jscript.runtime.EventLoop; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; -import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; import me.topchetoeu.jscript.runtime.values.Member.FieldMember; import me.topchetoeu.jscript.runtime.values.Member.PropertyMember; import me.topchetoeu.jscript.runtime.values.functions.FunctionValue; @@ -239,8 +239,8 @@ public abstract class Value { public final boolean setMember(Environment env, KeyCache key, Value val) { for (Value obj = this; obj != null; obj = obj.getPrototype(env)) { var member = obj.getOwnMember(env, key); - if (member instanceof PropertyMember prop) { - if (prop.set(env, val, obj)) { + if (member != null && (member instanceof PropertyMember || obj == this)) { + if (member.set(env, val, obj)) { if (val instanceof FunctionValue) ((FunctionValue)val).setName(key.toString(env)); return true; } diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/objects/ObjectValue.java b/src/main/java/me/topchetoeu/jscript/runtime/values/objects/ObjectValue.java index b48b1a1..888ca35 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/objects/ObjectValue.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/objects/ObjectValue.java @@ -72,8 +72,9 @@ public class ObjectValue extends Value { @Override public final void freeze() { state = State.FROZEN; } @Override public Member getOwnMember(Environment env, KeyCache key) { - if (key.isSymbol()) return symbolMembers.get(key.toSymbol()); - else return members.get(key.toString(env)); + if (symbolMembers.size() > 0 && key.isSymbol()) return symbolMembers.get(key.toSymbol()); + else if (members.size() > 0) return members.get(key.toString(env)); + else return null; } @Override public boolean defineOwnMember(Environment env, KeyCache key, Member member) { var old = getOwnMember(env, key);