فهرست منبع

LibJS: Remove ErrorType::FixmeAddAnErrorStringWithMessage

davidot 3 سال پیش
والد
کامیت
c3cb44ca8a

+ 6 - 6
Userland/Libraries/LibJS/AST.cpp

@@ -3213,7 +3213,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
 {
 {
     for_each_lexically_declared_name([&](FlyString const& name) {
     for_each_lexically_declared_name([&](FlyString const& name) {
         if (global_environment.has_var_declaration(name) || global_environment.has_lexical_declaration(name)) {
         if (global_environment.has_var_declaration(name) || global_environment.has_lexical_declaration(name)) {
-            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Lexical variable top level already declared");
+            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::TopLevelVariableAlreadyDeclared, name);
             return IterationDecision::Break;
             return IterationDecision::Break;
         }
         }
 
 
@@ -3222,7 +3222,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
             return IterationDecision::Break;
             return IterationDecision::Break;
 
 
         if (restricted_global)
         if (restricted_global)
-            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Restricted global property");
+            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::RestrictedGlobalProperty, name);
 
 
         return IterationDecision::Continue;
         return IterationDecision::Continue;
     });
     });
@@ -3232,7 +3232,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
 
 
     for_each_var_declared_name([&](auto const& name) {
     for_each_var_declared_name([&](auto const& name) {
         if (global_environment.has_lexical_declaration(name)) {
         if (global_environment.has_lexical_declaration(name)) {
-            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Var declared variable top level also lexically declared");
+            interpreter.vm().throw_exception<SyntaxError>(global_object, ErrorType::TopLevelVariableAlreadyDeclared, name);
             return IterationDecision::Break;
             return IterationDecision::Break;
         }
         }
 
 
@@ -3255,7 +3255,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
             return IterationDecision::Break;
             return IterationDecision::Break;
 
 
         if (!function_definable) {
         if (!function_definable) {
-            interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Global function not definable");
+            interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::CannotDeclareGlobalFunction, function.name());
             return IterationDecision::Break;
             return IterationDecision::Break;
         }
         }
 
 
@@ -3278,7 +3278,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
                 return IterationDecision::Break;
                 return IterationDecision::Break;
 
 
             if (!var_definable) {
             if (!var_definable) {
-                interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Global variable not definable");
+                interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::CannotDeclareGlobalVariable, name);
                 return IterationDecision::Break;
                 return IterationDecision::Break;
             }
             }
 
 
@@ -3305,7 +3305,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
                 return IterationDecision::Break;
                 return IterationDecision::Break;
 
 
             if (!function_definable) {
             if (!function_definable) {
-                interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Global function not definable");
+                interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::CannotDeclareGlobalFunction, function_name);
                 return IterationDecision::Break;
                 return IterationDecision::Break;
             }
             }
 
 

+ 4 - 4
Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

@@ -547,7 +547,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
         if (global_var_environment) {
         if (global_var_environment) {
             program.for_each_var_declared_name([&](auto const& name) {
             program.for_each_var_declared_name([&](auto const& name) {
                 if (global_var_environment->has_lexical_declaration(name)) {
                 if (global_var_environment->has_lexical_declaration(name)) {
-                    vm.throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Var already declared lexically");
+                    vm.throw_exception<SyntaxError>(global_object, ErrorType::TopLevelVariableAlreadyDeclared, name);
                     return IterationDecision::Break;
                     return IterationDecision::Break;
                 }
                 }
                 return IterationDecision::Continue;
                 return IterationDecision::Continue;
@@ -559,7 +559,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
             if (!is<ObjectEnvironment>(*this_environment)) {
             if (!is<ObjectEnvironment>(*this_environment)) {
                 program.for_each_var_declared_name([&](auto const& name) {
                 program.for_each_var_declared_name([&](auto const& name) {
                     if (MUST(this_environment->has_binding(name))) {
                     if (MUST(this_environment->has_binding(name))) {
-                        vm.throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Var already declared lexically");
+                        vm.throw_exception<SyntaxError>(global_object, ErrorType::TopLevelVariableAlreadyDeclared, name);
                         return IterationDecision::Break;
                         return IterationDecision::Break;
                     }
                     }
                     // FIXME: NOTE: Annex B.3.4 defines alternate semantics for the above step.
                     // FIXME: NOTE: Annex B.3.4 defines alternate semantics for the above step.
@@ -586,7 +586,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
             if (vm.exception())
             if (vm.exception())
                 return IterationDecision::Break;
                 return IterationDecision::Break;
             if (!function_definable) {
             if (!function_definable) {
-                vm.throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Cannot define global function");
+                vm.throw_exception<TypeError>(global_object, ErrorType::CannotDeclareGlobalFunction, function.name());
                 return IterationDecision::Break;
                 return IterationDecision::Break;
             }
             }
         }
         }
@@ -656,7 +656,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
                     if (vm.exception())
                     if (vm.exception())
                         return IterationDecision::Break;
                         return IterationDecision::Break;
                     if (!variable_definable) {
                     if (!variable_definable) {
-                        vm.throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Cannot define global var");
+                        vm.throw_exception<TypeError>(global_object, ErrorType::CannotDeclareGlobalVariable, name);
                         return IterationDecision::Break;
                         return IterationDecision::Break;
                     }
                     }
                 }
                 }

+ 4 - 1
Userland/Libraries/LibJS/Runtime/ErrorTypes.h

@@ -16,6 +16,8 @@
     M(BigIntInvalidValue, "Invalid value for BigInt: {}")                                                                               \
     M(BigIntInvalidValue, "Invalid value for BigInt: {}")                                                                               \
     M(BindingNotInitialized, "Binding {} is not initialized")                                                                           \
     M(BindingNotInitialized, "Binding {} is not initialized")                                                                           \
     M(CallStackSizeExceeded, "Call stack size limit exceeded")                                                                          \
     M(CallStackSizeExceeded, "Call stack size limit exceeded")                                                                          \
+    M(CannotDeclareGlobalFunction, "Cannot declare global function of name '{}'")                                                       \
+    M(CannotDeclareGlobalVariable, "Cannot declare global variable of name '{}'")                                                       \
     M(ClassConstructorWithoutNew, "Class constructor {} must be called with 'new'")                                                     \
     M(ClassConstructorWithoutNew, "Class constructor {} must be called with 'new'")                                                     \
     M(ClassExtendsValueNotAConstructorOrNull, "Class extends value {} is not a constructor or null")                                    \
     M(ClassExtendsValueNotAConstructorOrNull, "Class extends value {} is not a constructor or null")                                    \
     M(ClassExtendsValueInvalidPrototype, "Class extends value has an invalid prototype {}")                                             \
     M(ClassExtendsValueInvalidPrototype, "Class extends value has an invalid prototype {}")                                             \
@@ -171,6 +173,7 @@
     M(RegExpObjectRepeatedFlag, "Repeated RegExp flag '{}'")                                                                            \
     M(RegExpObjectRepeatedFlag, "Repeated RegExp flag '{}'")                                                                            \
     M(RestrictedFunctionPropertiesAccess, "Restricted function properties like 'callee', 'caller' and 'arguments' may "                 \
     M(RestrictedFunctionPropertiesAccess, "Restricted function properties like 'callee', 'caller' and 'arguments' may "                 \
                                           "not be accessed in strict mode")                                                             \
                                           "not be accessed in strict mode")                                                             \
+    M(RestrictedGlobalProperty, "Cannot declare global property '{}'")                                                                  \
     M(ShadowRealmEvaluateAbruptCompletion, "The evaluated script did not complete normally")                                            \
     M(ShadowRealmEvaluateAbruptCompletion, "The evaluated script did not complete normally")                                            \
     M(ShadowRealmWrappedValueNonFunctionObject, "Wrapped value must be primitive or a function object, got {}")                         \
     M(ShadowRealmWrappedValueNonFunctionObject, "Wrapped value must be primitive or a function object, got {}")                         \
     M(SpeciesConstructorDidNotCreate, "Species constructor did not create {}")                                                          \
     M(SpeciesConstructorDidNotCreate, "Species constructor did not create {}")                                                          \
@@ -209,6 +212,7 @@
     M(ThisHasNotBeenInitialized, "|this| has not been initialized")                                                                     \
     M(ThisHasNotBeenInitialized, "|this| has not been initialized")                                                                     \
     M(ThisIsAlreadyInitialized, "|this| is already initialized")                                                                        \
     M(ThisIsAlreadyInitialized, "|this| is already initialized")                                                                        \
     M(ToObjectNullOrUndefined, "ToObject on null or undefined")                                                                         \
     M(ToObjectNullOrUndefined, "ToObject on null or undefined")                                                                         \
+    M(TopLevelVariableAlreadyDeclared, "Redeclaration of top level variable '{}'")                                                      \
     M(ToPrimitiveReturnedObject, "Can't convert {} to primitive with hint \"{}\", its @@toPrimitive method returned an object")         \
     M(ToPrimitiveReturnedObject, "Can't convert {} to primitive with hint \"{}\", its @@toPrimitive method returned an object")         \
     M(TypedArrayContentTypeMismatch, "Can't create {} from {}")                                                                         \
     M(TypedArrayContentTypeMismatch, "Can't create {} from {}")                                                                         \
     M(TypedArrayInvalidBufferLength, "Invalid buffer length for {}: must be a multiple of {}, got {}")                                  \
     M(TypedArrayInvalidBufferLength, "Invalid buffer length for {}: must be a multiple of {}, got {}")                                  \
@@ -227,7 +231,6 @@
     M(BadArgCountAtLeastOne, "{}() needs at least one argument")                                                                        \
     M(BadArgCountAtLeastOne, "{}() needs at least one argument")                                                                        \
     M(BadArgCountMany, "{}() needs {} arguments")                                                                                       \
     M(BadArgCountMany, "{}() needs {} arguments")                                                                                       \
     M(FixmeAddAnErrorString, "FIXME: Add a string for this error.")                                                                     \
     M(FixmeAddAnErrorString, "FIXME: Add a string for this error.")                                                                     \
-    M(FixmeAddAnErrorStringWithMessage, "FIXME: Add a real string for this error '{}'")                                                 \
     M(NotEnoughMemoryToAllocate, "Not enough memory to allocate {} bytes")
     M(NotEnoughMemoryToAllocate, "Not enough memory to allocate {} bytes")
 
 
 namespace JS {
 namespace JS {