Skip to content

Commit b2323ec

Browse files
committed
[JSC] Move String#search related JIT operations from runtime/StringPrototype to dfg/DFGOperations
https://bugs.webkit.org/show_bug.cgi?id=290249 Reviewed by Yusuke Suzuki. Unlike many other JIT operations, the definitions and declarations of the JIT operations related to `String#search` and `String#searchAll` are located in `runtime/StringPrototype.h` and `runtime/StringPrototype.cpp`, rather than in `dfg/DFGOperations.h` and `dfg/DFGOperations.cpp`. This patch moves those JIT operations to `dfg/DFGOperations` for consistency with the rest of the codebase. It also moves dependent functions from `StringPrototype.cpp` to `StringPrototypeInlines.h`(The logic of the functions remains completely unchanged). * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/dfg/DFGOperations.h: * Source/JavaScriptCore/runtime/StringPrototype.cpp: (JSC::jsSpliceSubstrings): Deleted. (JSC::removeUsingRegExpSearch): Deleted. (JSC::replaceUsingRegExpSearchWithCache): Deleted. (JSC::tryTrimSpaces): Deleted. (JSC::replaceUsingRegExpSearch): Deleted. (JSC::JSC_DEFINE_JIT_OPERATION): Deleted. (JSC::checkObjectCoercible): Deleted. (JSC::replace): Deleted. * Source/JavaScriptCore/runtime/StringPrototype.h: * Source/JavaScriptCore/runtime/StringPrototypeInlines.h: (JSC::jsSpliceSubstrings): (JSC::removeUsingRegExpSearch): (JSC::replaceUsingRegExpSearchWithCache): (JSC::tryTrimSpaces): (JSC::replaceUsingRegExpSearch): (JSC::checkObjectCoercible): (JSC::replace): Canonical link: https://commits.webkit.org/292557@main
1 parent e5f7177 commit b2323ec

5 files changed

Lines changed: 924 additions & 922 deletions

File tree

Source/JavaScriptCore/dfg/DFGOperations.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,104 @@ JSC_DEFINE_JIT_OPERATION(operationStringIndexOfWithIndexWithOneChar, UCPUStrictI
32033203
OPERATION_RETURN(scope, toUCPUStrictInt32(result));
32043204
}
32053205

3206+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceGeneric, JSCell*, (JSGlobalObject* globalObject, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue))
3207+
{
3208+
VM& vm = globalObject->vm();
3209+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3210+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3211+
auto scope = DECLARE_THROW_SCOPE(vm);
3212+
3213+
OPERATION_RETURN(scope, replace(vm, globalObject, JSValue::decode(thisValue), JSValue::decode(searchValue), JSValue::decode(replaceValue), StringReplaceMode::Single));
3214+
}
3215+
3216+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceAllGeneric, JSCell*, (JSGlobalObject* globalObject, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue))
3217+
{
3218+
VM& vm = globalObject->vm();
3219+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3220+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3221+
auto scope = DECLARE_THROW_SCOPE(vm);
3222+
3223+
OPERATION_RETURN(scope, replace(vm, globalObject, JSValue::decode(thisValue), JSValue::decode(searchValue), JSValue::decode(replaceValue), StringReplaceMode::Global));
3224+
}
3225+
3226+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceRegExpEmptyStr, JSCell*, (JSGlobalObject* globalObject, JSString* thisValue, RegExpObject* searchValue))
3227+
{
3228+
VM& vm = globalObject->vm();
3229+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3230+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3231+
auto scope = DECLARE_THROW_SCOPE(vm);
3232+
3233+
RegExp* regExp = searchValue->regExp();
3234+
if (regExp->global()) {
3235+
// ES5.1 15.5.4.10 step 8.a.
3236+
searchValue->setLastIndex(globalObject, 0);
3237+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3238+
auto source = thisValue->value(globalObject);
3239+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3240+
OPERATION_RETURN(scope, removeUsingRegExpSearch(vm, globalObject, thisValue, source, regExp));
3241+
}
3242+
3243+
CallData callData;
3244+
String replacementString = emptyString();
3245+
OPERATION_RETURN(scope, replaceUsingRegExpSearch(
3246+
vm, globalObject, thisValue, searchValue, callData, replacementString, JSValue()));
3247+
}
3248+
3249+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceAllRegExpEmptyStr, JSCell*, (JSGlobalObject* globalObject, JSString* thisValue, RegExpObject* searchValue))
3250+
{
3251+
VM& vm = globalObject->vm();
3252+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3253+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3254+
auto scope = DECLARE_THROW_SCOPE(vm);
3255+
3256+
RegExp* regExp = searchValue->regExp();
3257+
3258+
if (UNLIKELY(!regExp->global())) {
3259+
throwTypeError(globalObject, scope, "String.prototype.replaceAll argument must not be a non-global regular expression"_s);
3260+
OPERATION_RETURN(scope, nullptr);
3261+
}
3262+
3263+
// ES5.1 15.5.4.10 step 8.a.
3264+
searchValue->setLastIndex(globalObject, 0);
3265+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3266+
auto source = thisValue->value(globalObject);
3267+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3268+
OPERATION_RETURN(scope, removeUsingRegExpSearch(vm, globalObject, thisValue, source, regExp));
3269+
}
3270+
3271+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceRegExpString, JSCell*, (JSGlobalObject* globalObject, JSString* thisValue, RegExpObject* searchValue, JSString* replaceString))
3272+
{
3273+
VM& vm = globalObject->vm();
3274+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3275+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3276+
auto scope = DECLARE_THROW_SCOPE(vm);
3277+
3278+
CallData callData;
3279+
auto replacementString = replaceString->value(globalObject);
3280+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3281+
OPERATION_RETURN(scope, replaceUsingRegExpSearch(
3282+
vm, globalObject, thisValue, searchValue, callData, replacementString, replaceString));
3283+
}
3284+
3285+
JSC_DEFINE_JIT_OPERATION(operationStringProtoFuncReplaceAllRegExpString, JSCell*, (JSGlobalObject* globalObject, JSString* thisValue, RegExpObject* searchValue, JSString* replaceString))
3286+
{
3287+
VM& vm = globalObject->vm();
3288+
CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
3289+
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
3290+
auto scope = DECLARE_THROW_SCOPE(vm);
3291+
3292+
if (UNLIKELY(!searchValue->regExp()->global())) {
3293+
throwTypeError(globalObject, scope, "String.prototype.replaceAll argument must not be a non-global regular expression"_s);
3294+
OPERATION_RETURN(scope, nullptr);
3295+
}
3296+
3297+
CallData callData;
3298+
auto replacementString = replaceString->value(globalObject);
3299+
OPERATION_RETURN_IF_EXCEPTION(scope, nullptr);
3300+
OPERATION_RETURN(scope, replaceUsingRegExpSearch(
3301+
vm, globalObject, thisValue, searchValue, callData, replacementString, replaceString));
3302+
}
3303+
32063304
JSC_DEFINE_JIT_OPERATION(operationInt32ToString, char*, (JSGlobalObject* globalObject, int32_t value, int32_t radix))
32073305
{
32083306
VM& vm = globalObject->vm();

Source/JavaScriptCore/dfg/DFGOperations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ JSC_DECLARE_JIT_OPERATION(operationStringIndexOfWithOneChar, UCPUStrictInt32, (J
287287
JSC_DECLARE_JIT_OPERATION(operationStringIndexOfWithIndex, UCPUStrictInt32, (JSGlobalObject*, JSString*, JSString*, int32_t));
288288
JSC_DECLARE_JIT_OPERATION(operationStringIndexOfWithIndexWithOneChar, UCPUStrictInt32, (JSGlobalObject*, JSString*, int32_t, int32_t));
289289

290+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceGeneric, JSCell*, (JSGlobalObject*, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue));
291+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceAllGeneric, JSCell*, (JSGlobalObject*, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue));
292+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceRegExpEmptyStr, JSCell*, (JSGlobalObject*, JSString* thisValue, RegExpObject* searchValue));
293+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceAllRegExpEmptyStr, JSCell*, (JSGlobalObject*, JSString* thisValue, RegExpObject* searchValue));
294+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceRegExpString, JSCell*, (JSGlobalObject*, JSString* thisValue, RegExpObject* searchValue, JSString* replaceValue));
295+
JSC_DECLARE_JIT_OPERATION(operationStringProtoFuncReplaceAllRegExpString, JSCell*, (JSGlobalObject*, JSString* thisValue, RegExpObject* searchValue, JSString* replaceValue));
296+
290297
JSC_DECLARE_JIT_OPERATION(operationInt32ToString, char*, (JSGlobalObject*, int32_t, int32_t));
291298
JSC_DECLARE_JIT_OPERATION(operationInt52ToString, char*, (JSGlobalObject*, int64_t, int32_t));
292299
JSC_DECLARE_JIT_OPERATION(operationDoubleToString, char*, (JSGlobalObject*, double, int32_t));

0 commit comments

Comments
 (0)