소스 검색

LibJS: Convert ShadowRealmPrototype functions to ThrowCompletionOr

Idan Horowitz 3 년 전
부모
커밋
040e29c7b9
2개의 변경된 파일14개의 추가작업 그리고 16개의 파일을 삭제
  1. 12 14
      Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp
  2. 2 2
      Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.h

+ 12 - 14
Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp

@@ -22,27 +22,25 @@ void ShadowRealmPrototype::initialize(GlobalObject& global_object)
     Object::initialize(global_object);
 
     u8 attr = Attribute::Writable | Attribute::Configurable;
-    define_old_native_function(vm.names.evaluate, evaluate, 1, attr);
-    define_old_native_function(vm.names.importValue, import_value, 2, attr);
+    define_native_function(vm.names.evaluate, evaluate, 1, attr);
+    define_native_function(vm.names.importValue, import_value, 2, attr);
 
     // 3.4.3 ShadowRealm.prototype [ @@toStringTag ], https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype-@@tostringtag
     define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.ShadowRealm.as_string()), Attribute::Configurable);
 }
 
 // 3.4.1 ShadowRealm.prototype.evaluate ( sourceText ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.evaluate
-JS_DEFINE_OLD_NATIVE_FUNCTION(ShadowRealmPrototype::evaluate)
+JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::evaluate)
 {
     auto source_text = vm.argument(0);
 
     // 1. Let O be this value.
     // 2. Perform ? ValidateShadowRealmObject(O).
-    auto* object = TRY_OR_DISCARD(typed_this_object(global_object));
+    auto* object = TRY(typed_this_object(global_object));
 
     // 3. If Type(sourceText) is not String, throw a TypeError exception.
-    if (!source_text.is_string()) {
-        vm.throw_exception<TypeError>(global_object, ErrorType::NotAString, source_text);
-        return {};
-    }
+    if (!source_text.is_string())
+        return vm.throw_completion<TypeError>(global_object, ErrorType::NotAString, source_text);
 
     // 4. Let callerRealm be the current Realm Record.
     auto* caller_realm = vm.current_realm();
@@ -51,24 +49,24 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ShadowRealmPrototype::evaluate)
     auto& eval_realm = object->shadow_realm();
 
     // 6. Return ? PerformShadowRealmEval(sourceText, callerRealm, evalRealm).
-    return TRY_OR_DISCARD(perform_shadow_realm_eval(global_object, source_text.as_string().string(), *caller_realm, eval_realm));
+    return perform_shadow_realm_eval(global_object, source_text.as_string().string(), *caller_realm, eval_realm);
 }
 
 // 3.4.2 ShadowRealm.prototype.importValue ( specifier, exportName ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.importvalue
-JS_DEFINE_OLD_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
+JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
 {
     auto specifier = vm.argument(0);
     auto export_name = vm.argument(1);
 
     // 1. Let O be this value.
     // 2. Perform ? ValidateShadowRealmObject(O).
-    auto* object = TRY_OR_DISCARD(typed_this_object(global_object));
+    auto* object = TRY(typed_this_object(global_object));
 
     // 3. Let specifierString be ? ToString(specifier).
-    auto specifier_string = TRY_OR_DISCARD(specifier.to_string(global_object));
+    auto specifier_string = TRY(specifier.to_string(global_object));
 
     // 4. Let exportNameString be ? ToString(exportName).
-    auto export_name_string = TRY_OR_DISCARD(export_name.to_string(global_object));
+    auto export_name_string = TRY(export_name.to_string(global_object));
 
     // 5. Let callerRealm be the current Realm Record.
     auto* caller_realm = vm.current_realm();
@@ -80,7 +78,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
     auto& eval_context = object->execution_context();
 
     // 8. Return ? ShadowRealmImportValue(specifierString, exportNameString, callerRealm, evalRealm, evalContext).
-    return TRY_OR_DISCARD(shadow_realm_import_value(global_object, move(specifier_string), move(export_name_string), *caller_realm, eval_realm, eval_context));
+    return shadow_realm_import_value(global_object, move(specifier_string), move(export_name_string), *caller_realm, eval_realm, eval_context);
 }
 
 }

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.h

@@ -20,8 +20,8 @@ public:
     virtual ~ShadowRealmPrototype() override = default;
 
 private:
-    JS_DECLARE_OLD_NATIVE_FUNCTION(evaluate);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(import_value);
+    JS_DECLARE_NATIVE_FUNCTION(evaluate);
+    JS_DECLARE_NATIVE_FUNCTION(import_value);
 };
 
 }