58 59 /** Property or field value as object. */ 60 final Object valueAsObject; 61 62 /** Property or field value as string. */ 63 final String valueAsString; 64 65 DebuggerValueDesc(final String key, final boolean expandable, final Object valueAsObject, final String valueAsString) { 66 this.key = key; 67 this.expandable = expandable; 68 this.valueAsObject = valueAsObject; 69 this.valueAsString = valueAsString; 70 } 71 } 72 73 /** 74 * Return the current context global. 75 * @return context global. 76 */ 77 static Object getGlobal() { 78 return Context.getGlobalTrusted(); 79 } 80 81 /** 82 * Call eval on the current global. 83 * @param scope Scope to use. 84 * @param self Receiver to use. 85 * @param string String to evaluate. 86 * @param returnException true if exceptions are to be returned. 87 * @return Result of eval as string, or, an exception or null depending on returnException. 88 */ 89 static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) { 90 final ScriptObject global = Context.getGlobalTrusted(); 91 final ScriptObject initialScope = scope != null ? scope : global; 92 final Object callThis = self != null ? self : global; 93 final Context context = global.getContext(); 94 95 try { 96 return context.eval(initialScope, string, callThis, ScriptRuntime.UNDEFINED, false); 97 } catch (Throwable ex) { 98 return returnException ? ex : null; 99 } 100 } 101 102 /** 103 * This method returns a bulk description of an object's properties. 104 * @param object Script object to be displayed by the debugger. 105 * @param all true if to include non-enumerable values. 106 * @return An array of DebuggerValueDesc. 107 */ 108 static DebuggerValueDesc[] valueInfos(final Object object, final boolean all) { 109 assert object instanceof ScriptObject; 110 return getDebuggerValueDescs((ScriptObject)object, all, new HashSet<>()); | 58 59 /** Property or field value as object. */ 60 final Object valueAsObject; 61 62 /** Property or field value as string. */ 63 final String valueAsString; 64 65 DebuggerValueDesc(final String key, final boolean expandable, final Object valueAsObject, final String valueAsString) { 66 this.key = key; 67 this.expandable = expandable; 68 this.valueAsObject = valueAsObject; 69 this.valueAsString = valueAsString; 70 } 71 } 72 73 /** 74 * Return the current context global. 75 * @return context global. 76 */ 77 static Object getGlobal() { 78 return Context.getGlobal(); 79 } 80 81 /** 82 * Call eval on the current global. 83 * @param scope Scope to use. 84 * @param self Receiver to use. 85 * @param string String to evaluate. 86 * @param returnException true if exceptions are to be returned. 87 * @return Result of eval as string, or, an exception or null depending on returnException. 88 */ 89 static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) { 90 final ScriptObject global = Context.getGlobal(); 91 final ScriptObject initialScope = scope != null ? scope : global; 92 final Object callThis = self != null ? self : global; 93 final Context context = global.getContext(); 94 95 try { 96 return context.eval(initialScope, string, callThis, ScriptRuntime.UNDEFINED, false); 97 } catch (Throwable ex) { 98 return returnException ? ex : null; 99 } 100 } 101 102 /** 103 * This method returns a bulk description of an object's properties. 104 * @param object Script object to be displayed by the debugger. 105 * @param all true if to include non-enumerable values. 106 * @return An array of DebuggerValueDesc. 107 */ 108 static DebuggerValueDesc[] valueInfos(final Object object, final boolean all) { 109 assert object instanceof ScriptObject; 110 return getDebuggerValueDescs((ScriptObject)object, all, new HashSet<>()); |