src/jdk/nashorn/internal/runtime/ECMAErrors.java

Print this page

        

@@ -29,10 +29,11 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 import jdk.nashorn.api.scripting.NashornException;
 import jdk.nashorn.internal.scripts.JS;
 import jdk.nashorn.internal.codegen.CompilerConstants;
+import jdk.nashorn.internal.objects.Global;
 
 /**
  * Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc.
  */
 public final class ECMAErrors {

@@ -64,11 +65,11 @@
      * @param e {@code ParserException} for error dispatcher
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException asEcmaException(final ParserException e) {
-        return asEcmaException(Context.getGlobalTrusted(), e);
+        return asEcmaException(Context.getGlobal(), e);
     }
 
     /**
      * Error dispatch mechanism.
      * Create a {@link ParserException} as the correct JavaScript error

@@ -76,15 +77,15 @@
      * @param global global scope object
      * @param e {@code ParserException} for error dispatcher
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException asEcmaException(final ScriptObject global, final ParserException e) {
+    public static ECMAException asEcmaException(final Global global, final ParserException e) {
         final JSErrorType errorType = e.getErrorType();
         assert errorType != null : "error type for " + e + " was null";
 
-        final GlobalObject globalObj = (GlobalObject)global;
+        final Global globalObj    = global;
         final String       msg    = e.getMessage();
 
         // translate to ECMAScript Error object using error type
         switch (errorType) {
         case ERROR:

@@ -114,11 +115,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException syntaxError(final String msgId, final String... args) {
-        return syntaxError(Context.getGlobalTrusted(), msgId, args);
+        return syntaxError(Context.getGlobal(), msgId, args);
     }
 
     /**
      * Create a syntax error (ECMA 15.11.6.4)
      *

@@ -126,11 +127,11 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException syntaxError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException syntaxError(final Global global, final String msgId, final String... args) {
         return syntaxError(global, null, msgId, args);
     }
 
     /**
      * Create a syntax error (ECMA 15.11.6.4)

@@ -140,11 +141,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException syntaxError(final Throwable cause, final String msgId, final String... args) {
-        return syntaxError(Context.getGlobalTrusted(), cause, msgId, args);
+        return syntaxError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
      * Create a syntax error (ECMA 15.11.6.4)
      *

@@ -153,13 +154,13 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException syntaxError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException syntaxError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("syntax.error." + msgId, args);
-        return error(((GlobalObject)global).newSyntaxError(msg), cause);
+        return error(global.newSyntaxError(msg), cause);
     }
 
     /**
      * Create a type error (ECMA 15.11.6.5)
      *

@@ -167,11 +168,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException typeError(final String msgId, final String... args) {
-        return typeError(Context.getGlobalTrusted(), msgId, args);
+        return typeError(Context.getGlobal(), msgId, args);
     }
 
     /**
      * Create a type error (ECMA 15.11.6.5)
      *

@@ -179,11 +180,11 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException typeError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException typeError(final Global global, final String msgId, final String... args) {
         return typeError(global, null, msgId, args);
     }
 
     /**
      * Create a type error (ECMA 15.11.6.5)

@@ -193,11 +194,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException typeError(final Throwable cause, final String msgId, final String... args) {
-        return typeError(Context.getGlobalTrusted(), cause, msgId, args);
+        return typeError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
      * Create a type error (ECMA 15.11.6.5)
      *

@@ -206,13 +207,13 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException typeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException typeError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("type.error." + msgId, args);
-        return error(((GlobalObject)global).newTypeError(msg), cause);
+        return error(global.newTypeError(msg), cause);
     }
 
     /**
      * Create a range error (ECMA 15.11.6.2)
      *

@@ -220,11 +221,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException rangeError(final String msgId, final String... args) {
-        return rangeError(Context.getGlobalTrusted(), msgId, args);
+        return rangeError(Context.getGlobal(), msgId, args);
     }
 
     /**
      * Create a range error (ECMA 15.11.6.2)
      *

@@ -232,11 +233,11 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException rangeError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException rangeError(final Global global, final String msgId, final String... args) {
         return rangeError(global, null, msgId, args);
     }
 
     /**
      * Create a range error (ECMA 15.11.6.2)

@@ -246,11 +247,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException rangeError(final Throwable cause, final String msgId, final String... args) {
-        return rangeError(Context.getGlobalTrusted(), cause, msgId, args);
+        return rangeError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
      * Create a range error (ECMA 15.11.6.2)
      *

@@ -259,13 +260,13 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException rangeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException rangeError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("range.error." + msgId, args);
-        return error(((GlobalObject)global).newRangeError(msg), cause);
+        return error(global.newRangeError(msg), cause);
     }
 
     /**
      * Create a reference error (ECMA 15.11.6.3)
      *

@@ -273,11 +274,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException referenceError(final String msgId, final String... args) {
-        return referenceError(Context.getGlobalTrusted(), msgId, args);
+        return referenceError(Context.getGlobal(), msgId, args);
     }
 
     /**
      * Create a reference error (ECMA 15.11.6.3)
      *

@@ -285,11 +286,11 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException referenceError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException referenceError(final Global global, final String msgId, final String... args) {
         return referenceError(global, null, msgId, args);
     }
 
     /**
      * Create a reference error (ECMA 15.11.6.3)

@@ -299,11 +300,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException referenceError(final Throwable cause, final String msgId, final String... args) {
-        return referenceError(Context.getGlobalTrusted(), cause, msgId, args);
+        return referenceError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
      * Create a reference error (ECMA 15.11.6.3)
      *

@@ -312,13 +313,13 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException referenceError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException referenceError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("reference.error." + msgId, args);
-        return error(((GlobalObject)global).newReferenceError(msg), cause);
+        return error(global.newReferenceError(msg), cause);
     }
 
     /**
      * Create a URI error (ECMA 15.11.6.6)
      *

@@ -326,11 +327,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException uriError(final String msgId, final String... args) {
-        return uriError(Context.getGlobalTrusted(), msgId, args);
+        return uriError(Context.getGlobal(), msgId, args);
     }
 
     /**
      * Create a URI error (ECMA 15.11.6.6)
      *

@@ -338,11 +339,11 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException uriError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException uriError(final Global global, final String msgId, final String... args) {
         return uriError(global, null, msgId, args);
     }
 
     /**
      * Create a URI error (ECMA 15.11.6.6)

@@ -352,11 +353,11 @@
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException uriError(final Throwable cause, final String msgId, final String... args) {
-        return uriError(Context.getGlobalTrusted(), cause, msgId, args);
+        return uriError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
      * Create a URI error (ECMA 15.11.6.6)
      *

@@ -365,13 +366,13 @@
      * @param msgId   resource tag for error message
      * @param args    arguments to resource
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException uriError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException uriError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("uri.error." + msgId, args);
-        return error(((GlobalObject)global).newURIError(msg), cause);
+        return error(global.newURIError(msg), cause);
     }
 
     /**
      * Get the exception message by placing the args in the resource defined
      * by the resource tag. This is visible to, e.g. the {@link jdk.nashorn.internal.parser.Parser}