Class StrictModeHelper

java.lang.Object
org.mozilla.javascript.StrictModeHelper

public class StrictModeHelper extends Object
Helper class for handling strict mode compliance warnings. This class provides utilities to log warnings for strict mode violations that would have been errors in newer versions of Rhino (post 1.7.7.1). To maintain backward compatibility with Rhino 1.7.7.1, strict mode checks added after that version now log warnings instead of throwing errors. The warnings include the full error message that would have been thrown, providing complete information about the violation.
  • Constructor Details

    • StrictModeHelper

      public StrictModeHelper()
  • Method Details

    • warnStrictMode

      public static void warnStrictMode(Context cx, String messageId, Object... args)
      Log a strict mode warning instead of throwing an error. This is used for strict mode compliance checks added after Rhino 1.7.7.1.
      Parameters:
      cx - the current context
      messageId - the message ID from Messages.properties
      args - optional arguments for the message
    • warnStrictModeReferenceError

      public static void warnStrictModeReferenceError(Context cx, String errorMessage)
      Log a strict mode warning for ReferenceError violations. Similar to warnStrictMode but specifically for reference errors.
      Parameters:
      cx - the current context
      errorMessage - the complete error message
    • shouldThrowStrictError

      public static boolean shouldThrowStrictError(Context cx)
      Check if we should throw an error for strict mode violations. Returns true if FEATURE_STRICT_MODE is enabled AND we're in strict mode. This preserves the old 1.7.7.1 behavior where FEATURE_STRICT_MODE would cause errors to be thrown.
      Parameters:
      cx - the current context
      Returns:
      true if errors should be thrown for strict mode violations