diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-12-17 15:12:37 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-12-21 14:56:00 +0100 |
commit | 4a915fc9fa27f1ea55310bf686a3c5705660db35 (patch) | |
tree | b8d4fcb3c64625287ea159a005b5e65e190d67d9 /Userland/Libraries | |
parent | c6e2b03073cb12034ded84d00c8345ef54a2ad5f (diff) | |
download | serenity-4a915fc9fa27f1ea55310bf686a3c5705660db35.zip |
LibJS: Add spec comments to RegExp.prototype.compile
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 8cfdd0ac9f..5e2c97009b 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -860,27 +860,33 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) // B.2.4.1 RegExp.prototype.compile ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp.prototype.compile JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::compile) { - auto* regexp_object = TRY(typed_this_object(global_object)); - auto pattern = vm.argument(0); auto flags = vm.argument(1); - Value pattern_value; - Value flags_value; + // 1. Let O be the this value. + // 2. Perform ? RequireInternalSlot(O, [[RegExpMatcher]]). + auto* regexp_object = TRY(typed_this_object(global_object)); + // 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal slot, then if (pattern.is_object() && is<RegExpObject>(pattern.as_object())) { + // a. If flags is not undefined, throw a TypeError exception. if (!flags.is_undefined()) return vm.throw_completion<TypeError>(global_object, ErrorType::NotUndefined, flags.to_string_without_side_effects()); auto& regexp_pattern = static_cast<RegExpObject&>(pattern.as_object()); - pattern_value = js_string(vm, regexp_pattern.pattern()); - flags_value = js_string(vm, regexp_pattern.flags()); - } else { - pattern_value = pattern; - flags_value = flags; + + // b. Let P be pattern.[[OriginalSource]]. + pattern = js_string(vm, regexp_pattern.pattern()); + + // c. Let F be pattern.[[OriginalFlags]]. + flags = js_string(vm, regexp_pattern.flags()); } + // 4. Else, + // a. Let P be pattern. + // b. Let F be flags. - return TRY(regexp_object->regexp_initialize(global_object, pattern_value, flags_value)); + // 5. Return ? RegExpInitialize(O, P, F). + return TRY(regexp_object->regexp_initialize(global_object, pattern, flags)); } } |