diff options
Diffstat (limited to 'src/bun.js/builtins')
49 files changed, 1521 insertions, 111 deletions
diff --git a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp index 159e2f45b..93e13369a 100644 --- a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp +++ b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp @@ -1,9 +1,14 @@ +// clang-format off +namespace Zig { class GlobalObject; } +#include "root.h" + /* * Copyright (c) 2015 Igalia * Copyright (c) 2015 Igalia S.L. * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/WebCoreJSBuiltins.cpp b/src/bun.js/builtins/WebCoreJSBuiltins.cpp index cf5345346..eedab6754 100644 --- a/src/bun.js/builtins/WebCoreJSBuiltins.cpp +++ b/src/bun.js/builtins/WebCoreJSBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * @@ -38,6 +39,7 @@ #include "ImportMetaObjectBuiltins.cpp" #include "JSBufferConstructorBuiltins.cpp" #include "JSBufferPrototypeBuiltins.cpp" +#include "OnigurumaRegExpPrototypeBuiltins.cpp" #include "ProcessObjectBuiltins.cpp" #include "ReadableByteStreamControllerBuiltins.cpp" #include "ReadableByteStreamInternalsBuiltins.cpp" diff --git a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp index 3bec31ac7..fac21b4ec 100644 --- a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h index fc56f2911..b86a05c27 100644 --- a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h +++ b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp index ed428601a..82aaefddb 100644 --- a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp +++ b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h index 06811f00a..a05d5c9b8 100644 --- a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h +++ b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp index 360168176..75a52c699 100644 --- a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.h b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.h index 5cc424ec8..f3182273c 100644 --- a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.h +++ b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp index ed14b6699..1ec885ee0 100644 --- a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp +++ b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h index f9181b402..67670d715 100644 --- a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h +++ b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp index 67a829d74..d1d9231e7 100644 --- a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp +++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h index 8b85e9f23..f17f22dbb 100644 --- a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h +++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.cpp b/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.cpp new file mode 100644 index 000000000..cf55745b1 --- /dev/null +++ b/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.cpp @@ -0,0 +1,672 @@ +/* + * Copyright (c) 2015 Igalia + * Copyright (c) 2015 Igalia S.L. + * Copyright (c) 2015 Igalia. + * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. + * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#include "config.h" +#include "OnigurumaRegExpPrototypeBuiltins.h" + +#include "WebCoreJSClientData.h" +#include <JavaScriptCore/HeapInlines.h> +#include <JavaScriptCore/IdentifierInlines.h> +#include <JavaScriptCore/ImplementationVisibility.h> +#include <JavaScriptCore/Intrinsic.h> +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <JavaScriptCore/JSCellInlines.h> +#include <JavaScriptCore/StructureInlines.h> +#include <JavaScriptCore/VM.h> + +namespace WebCore { + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeAdvanceStringIndexCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeAdvanceStringIndexCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeAdvanceStringIndexCodeImplementationVisibility = JSC::ImplementationVisibility::Private; +const int s_onigurumaRegExpPrototypeAdvanceStringIndexCodeLength = 427; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeAdvanceStringIndexCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeAdvanceStringIndexCode = + "(function (string, index, unicode)\n" \ + "{\n" \ + " //\n" \ + " \"use strict\";\n" \ + "\n" \ + " if (!unicode)\n" \ + " return index + 1;\n" \ + "\n" \ + " if (index + 1 >= string.length)\n" \ + " return index + 1;\n" \ + "\n" \ + " var first = string.@charCodeAt(index);\n" \ + " if (first < 0xD800 || first > 0xDBFF)\n" \ + " return index + 1;\n" \ + "\n" \ + " var second = string.@charCodeAt(index + 1);\n" \ + " if (second < 0xDC00 || second > 0xDFFF)\n" \ + " return index + 1;\n" \ + "\n" \ + " return index + 2;\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchSlowCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchSlowCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchSlowCodeImplementationVisibility = JSC::ImplementationVisibility::Private; +const int s_onigurumaRegExpPrototypeMatchSlowCodeLength = 796; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeMatchSlowCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeMatchSlowCode = + "(function (regexp, str)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " if (!regexp.global)\n" \ + " return regexp.exec(str);\n" \ + " \n" \ + " var unicode = regexp.unicode;\n" \ + " regexp.lastIndex = 0;\n" \ + " var resultList = [];\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " //\n" \ + " var maximumReasonableMatchSize = 100000000;\n" \ + "\n" \ + " while (true) {\n" \ + " var result = regexp.exec(str);\n" \ + " \n" \ + " if (result === null) {\n" \ + " if (resultList.length === 0)\n" \ + " return null;\n" \ + " return resultList;\n" \ + " }\n" \ + "\n" \ + " if (resultList.length > maximumReasonableMatchSize)\n" \ + " @throwOutOfMemoryError();\n" \ + "\n" \ + " var resultString = @toString(result[0]);\n" \ + "\n" \ + " if (!resultString.length)\n" \ + " regexp.lastIndex = @advanceStringIndex(str, regexp.lastIndex, unicode);\n" \ + "\n" \ + " @arrayPush(resultList, resultString);\n" \ + " }\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeMatchCodeLength = 225; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeMatchCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeMatchCode = + "(function (strArg)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " if (!@isObject(this))\n" \ + " @throwTypeError(\"RegExp.prototype.@@match requires that |this| be an Object\");\n" \ + "\n" \ + " var str = @toString(strArg);\n" \ + "\n" \ + " return @matchSlow(this, str);\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchAllCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchAllCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchAllCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeMatchAllCodeLength = 2928; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeMatchAllCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeMatchAllCode = + "(function (strArg)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " var regExp = this;\n" \ + " if (!@isObject(regExp)) {\n" \ + " @throwTypeError(\"RegExp.prototype.@@matchAll requires |this| to be an Object\");\n" \ + " }\n" \ + "\n" \ + " var string = @toString(strArg);\n" \ + "\n" \ + " var Matcher = @speciesConstructor(regExp, @Bun.OnigurumaRegExp);\n" \ + "\n" \ + " var flags = @toString(regExp.flags);\n" \ + " var matcher = new Matcher(regExp.source, flags);\n" \ + " matcher.lastIndex = @toLength(regExp.lastIndex);\n" \ + "\n" \ + " var global = @stringIncludesInternal.@call(flags, \"g\");\n" \ + " var fullUnicode = @stringIncludesInternal.@call(flags, \"u\");\n" \ + "\n" \ + " var iterator = globalThis.Symbol.iterator;\n" \ + "\n" \ + " var RegExpStringIterator = class RegExpStringIterator {\n" \ + " constructor(regExp, string, global, fullUnicode)\n" \ + " {\n" \ + " \n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorRegExp\", regExp);\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorString\", string);\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorGlobal\", global);\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorUnicode\", fullUnicode);\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorDone\", false);\n" \ + " }\n" \ + "\n" \ + " next() {\n" \ + " \"use strict\";\n" \ + " if (!@isObject(this)) {\n" \ + " @throwTypeError(\"%RegExpStringIteratorPrototype%.next requires |this| to be an Object\");\n" \ + " }\n" \ + " \n" \ + " var done = @getByIdDirectPrivate(this, \"regExpStringIteratorDone\");\n" \ + " if (done === @undefined) {\n" \ + " @throwTypeError(\"%RegExpStringIteratorPrototype%.next requires |this| to be an RegExp String Iterator instance\");\n" \ + " }\n" \ + " \n" \ + " if (done) {\n" \ + " return { value: @undefined, done: true };\n" \ + " }\n" \ + " \n" \ + " var regExp = @getByIdDirectPrivate(this, \"regExpStringIteratorRegExp\");\n" \ + " var string = @getByIdDirectPrivate(this, \"regExpStringIteratorString\");\n" \ + " var global = @getByIdDirectPrivate(this, \"regExpStringIteratorGlobal\");\n" \ + " var fullUnicode = @getByIdDirectPrivate(this, \"regExpStringIteratorUnicode\");\n" \ + " var match = regExp.exec(string);\n" \ + " if (match === null) {\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorDone\", true);\n" \ + " return { value: @undefined, done: true };\n" \ + " }\n" \ + " \n" \ + " if (global) {\n" \ + " var matchStr = @toString(match[0]);\n" \ + " if (matchStr === \"\") {\n" \ + " var thisIndex = @toLength(regExp.lastIndex);\n" \ + " regExp.lastIndex = @advanceStringIndex(string, thisIndex, fullUnicode);\n" \ + " }\n" \ + " } else\n" \ + " @putByIdDirectPrivate(this, \"regExpStringIteratorDone\", true);\n" \ + " \n" \ + " return { value: match, done: false };\n" \ + " }\n" \ + "\n" \ + " [iterator]() {\n" \ + " return this;\n" \ + " }\n" \ + "\n" \ + " };\n" \ + "\n" \ + " return new RegExpStringIterator(matcher, string, global, fullUnicode);\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeGetSubstitutionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeGetSubstitutionCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeGetSubstitutionCodeImplementationVisibility = JSC::ImplementationVisibility::Private; +const int s_onigurumaRegExpPrototypeGetSubstitutionCodeLength = 3603; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeGetSubstitutionCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeGetSubstitutionCode = + "(function (matched, str, position, captures, namedCaptures, replacement)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " var matchLength = matched.length;\n" \ + " var stringLength = str.length;\n" \ + " var tailPos = position + matchLength;\n" \ + " var m = captures.length;\n" \ + " var replacementLength = replacement.length;\n" \ + " var result = \"\";\n" \ + " var lastStart = 0;\n" \ + "\n" \ + " for (var start = 0; start = @stringIndexOfInternal.@call(replacement, \"$\", lastStart), start !== -1; lastStart = start) {\n" \ + " if (start - lastStart > 0)\n" \ + " result = result + @stringSubstring.@call(replacement, lastStart, start);\n" \ + " start++;\n" \ + " if (start >= replacementLength)\n" \ + " result = result + \"$\";\n" \ + " else {\n" \ + " var ch = replacement[start];\n" \ + " switch (ch)\n" \ + " {\n" \ + " case \"$\":\n" \ + " result = result + \"$\";\n" \ + " start++;\n" \ + " break;\n" \ + " case \"&\":\n" \ + " result = result + matched;\n" \ + " start++;\n" \ + " break;\n" \ + " case \"`\":\n" \ + " if (position > 0)\n" \ + " result = result + @stringSubstring.@call(str, 0, position);\n" \ + " start++;\n" \ + " break;\n" \ + " case \"'\":\n" \ + " if (tailPos < stringLength)\n" \ + " result = result + @stringSubstring.@call(str, tailPos);\n" \ + " start++;\n" \ + " break;\n" \ + " case \"<\":\n" \ + " if (namedCaptures !== @undefined) {\n" \ + " var groupNameStartIndex = start + 1;\n" \ + " var groupNameEndIndex = @stringIndexOfInternal.@call(replacement, \">\", groupNameStartIndex);\n" \ + " if (groupNameEndIndex !== -1) {\n" \ + " var groupName = @stringSubstring.@call(replacement, groupNameStartIndex, groupNameEndIndex);\n" \ + " var capture = namedCaptures[groupName];\n" \ + " if (capture !== @undefined)\n" \ + " result = result + @toString(capture);\n" \ + "\n" \ + " start = groupNameEndIndex + 1;\n" \ + " break;\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " result = result + \"$<\";\n" \ + " start++;\n" \ + " break;\n" \ + " default:\n" \ + " var chCode = ch.@charCodeAt(0);\n" \ + " if (chCode >= 0x30 && chCode <= 0x39) {\n" \ + " var originalStart = start - 1;\n" \ + " start++;\n" \ + "\n" \ + " var n = chCode - 0x30;\n" \ + " if (n > m) {\n" \ + " result = result + @stringSubstring.@call(replacement, originalStart, start);\n" \ + " break;\n" \ + " }\n" \ + "\n" \ + " if (start < replacementLength) {\n" \ + " var nextChCode = replacement.@charCodeAt(start);\n" \ + " if (nextChCode >= 0x30 && nextChCode <= 0x39) {\n" \ + " var nn = 10 * n + nextChCode - 0x30;\n" \ + " if (nn <= m) {\n" \ + " n = nn;\n" \ + " start++;\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " if (n == 0) {\n" \ + " result = result + @stringSubstring.@call(replacement, originalStart, start);\n" \ + " break;\n" \ + " }\n" \ + "\n" \ + " var capture = captures[n - 1];\n" \ + " if (capture !== @undefined)\n" \ + " result = result + capture;\n" \ + " } else\n" \ + " result = result + \"$\";\n" \ + " break;\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " return result + @stringSubstring.@call(replacement, lastStart);\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeReplaceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeReplaceCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeReplaceCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeReplaceCodeLength = 3208; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeReplaceCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeReplaceCode = + "(function (strArg, replace)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " if (!@isObject(this))\n" \ + " @throwTypeError(\"RegExp.prototype.@@replace requires that |this| be an Object\");\n" \ + "\n" \ + " var regexp = this;\n" \ + "\n" \ + " var str = @toString(strArg);\n" \ + " var stringLength = str.length;\n" \ + " var functionalReplace = @isCallable(replace);\n" \ + "\n" \ + " if (!functionalReplace)\n" \ + " replace = @toString(replace);\n" \ + "\n" \ + " var global = regexp.global;\n" \ + " var unicode = false;\n" \ + "\n" \ + " if (global) {\n" \ + " unicode = regexp.unicode;\n" \ + " regexp.lastIndex = 0;\n" \ + " }\n" \ + "\n" \ + " var resultList = [];\n" \ + " var result;\n" \ + " var done = false;\n" \ + " while (!done) {\n" \ + " result = regexp.exec(str);\n" \ + "\n" \ + " if (result === null)\n" \ + " done = true;\n" \ + " else {\n" \ + " @arrayPush(resultList, result);\n" \ + " if (!global)\n" \ + " done = true;\n" \ + " else {\n" \ + " var matchStr = @toString(result[0]);\n" \ + "\n" \ + " if (!matchStr.length) {\n" \ + " var thisIndex = @toLength(regexp.lastIndex);\n" \ + " regexp.lastIndex = @advanceStringIndex(str, thisIndex, unicode);\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " var accumulatedResult = \"\";\n" \ + " var nextSourcePosition = 0;\n" \ + "\n" \ + " for (var i = 0, resultListLength = resultList.length; i < resultListLength; ++i) {\n" \ + " var result = resultList[i];\n" \ + " var nCaptures = result.length - 1;\n" \ + " if (nCaptures < 0)\n" \ + " nCaptures = 0;\n" \ + " var matched = @toString(result[0]);\n" \ + " var matchLength = matched.length;\n" \ + " var position = @toIntegerOrInfinity(result.index);\n" \ + " position = (position > stringLength) ? stringLength : position;\n" \ + " position = (position < 0) ? 0 : position;\n" \ + "\n" \ + " var captures = [];\n" \ + " for (var n = 1; n <= nCaptures; n++) {\n" \ + " var capN = result[n];\n" \ + " if (capN !== @undefined)\n" \ + " capN = @toString(capN);\n" \ + " @arrayPush(captures, capN);\n" \ + " }\n" \ + "\n" \ + " var replacement;\n" \ + " var namedCaptures = result.groups;\n" \ + "\n" \ + " if (functionalReplace) {\n" \ + " var replacerArgs = [ matched ];\n" \ + " for (var j = 0; j < captures.length; j++)\n" \ + " @arrayPush(replacerArgs, captures[j]);\n" \ + "\n" \ + " @arrayPush(replacerArgs, position);\n" \ + " @arrayPush(replacerArgs, str);\n" \ + "\n" \ + " if (namedCaptures !== @undefined)\n" \ + " @arrayPush(replacerArgs, namedCaptures);\n" \ + "\n" \ + " var replValue = replace.@apply(@undefined, replacerArgs);\n" \ + " replacement = @toString(replValue);\n" \ + " } else {\n" \ + " if (namedCaptures !== @undefined)\n" \ + " namedCaptures = @toObject(namedCaptures, \"RegExp.prototype[Symbol.replace] requires 'groups' property of a match not be null\");\n" \ + "\n" \ + " replacement = @getSubstitution(matched, str, position, captures, namedCaptures, replace);\n" \ + " }\n" \ + "\n" \ + " if (position >= nextSourcePosition) {\n" \ + " accumulatedResult = accumulatedResult + @stringSubstring.@call(str, nextSourcePosition, position) + replacement;\n" \ + " nextSourcePosition = position + matchLength;\n" \ + " }\n" \ + " }\n" \ + "\n" \ + " if (nextSourcePosition >= stringLength)\n" \ + " return accumulatedResult;\n" \ + "\n" \ + " return accumulatedResult + @stringSubstring.@call(str, nextSourcePosition);\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeSearchCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeSearchCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeSearchCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeSearchCodeLength = 631; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeSearchCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeSearchCode = + "(function (strArg)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " var regexp = this;\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " if (!@isObject(this))\n" \ + " @throwTypeError(\"RegExp.prototype.@@search requires that |this| be an Object\");\n" \ + "\n" \ + " //\n" \ + " var str = @toString(strArg)\n" \ + "\n" \ + " //\n" \ + " var previousLastIndex = regexp.lastIndex;\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " if (!@sameValue(previousLastIndex, 0))\n" \ + " regexp.lastIndex = 0;\n" \ + "\n" \ + " //\n" \ + " var result = regexp.exec(str);\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " //\n" \ + " if (!@sameValue(regexp.lastIndex, previousLastIndex))\n" \ + " regexp.lastIndex = previousLastIndex;\n" \ + "\n" \ + " //\n" \ + " if (result === null)\n" \ + " return -1;\n" \ + "\n" \ + " //\n" \ + " return result.index;\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeSplitCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeSplitCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeSplitCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeSplitCodeLength = 2926; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeSplitCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeSplitCode = + "(function (string, limit)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " if (!@isObject(this))\n" \ + " @throwTypeError(\"RegExp.prototype.@@split requires that |this| be an Object\");\n" \ + " var regexp = this;\n" \ + "\n" \ + " //\n" \ + " var str = @toString(string);\n" \ + "\n" \ + " //\n" \ + " var speciesConstructor = @speciesConstructor(regexp, @RegExp);\n" \ + "\n" \ + " //\n" \ + " var flags = @toString(regexp.flags);\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " var unicodeMatching = @stringIncludesInternal.@call(flags, \"u\");\n" \ + " //\n" \ + " //\n" \ + " var newFlags = @stringIncludesInternal.@call(flags, \"y\") ? flags : flags + \"y\";\n" \ + "\n" \ + " //\n" \ + " var splitter = new speciesConstructor(regexp.source, newFlags);\n" \ + "\n" \ + " //\n" \ + " //\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " var result = [];\n" \ + "\n" \ + " //\n" \ + " limit = (limit === @undefined) ? 0xffffffff : limit >>> 0;\n" \ + "\n" \ + " //\n" \ + " if (!limit)\n" \ + " return result;\n" \ + "\n" \ + " //\n" \ + " var size = str.length;\n" \ + "\n" \ + " //\n" \ + " if (!size) {\n" \ + " //\n" \ + " var z = splitter.exec(str);\n" \ + " //\n" \ + " if (z !== null)\n" \ + " return result;\n" \ + " //\n" \ + " @putByValDirect(result, 0, str);\n" \ + " //\n" \ + " return result;\n" \ + " }\n" \ + "\n" \ + " //\n" \ + " var position = 0;\n" \ + " //\n" \ + " var matchPosition = 0;\n" \ + "\n" \ + " //\n" \ + " while (matchPosition < size) {\n" \ + " //\n" \ + " splitter.lastIndex = matchPosition;\n" \ + " //\n" \ + " var matches = splitter.exec(str);\n" \ + " //\n" \ + " if (matches === null)\n" \ + " matchPosition = @advanceStringIndex(str, matchPosition, unicodeMatching);\n" \ + " //\n" \ + " else {\n" \ + " //\n" \ + " var endPosition = @toLength(splitter.lastIndex);\n" \ + " //\n" \ + " endPosition = (endPosition <= size) ? endPosition : size;\n" \ + " //\n" \ + " if (endPosition === position)\n" \ + " matchPosition = @advanceStringIndex(str, matchPosition, unicodeMatching);\n" \ + " //\n" \ + " else {\n" \ + " //\n" \ + " var subStr = @stringSubstring.@call(str, position, matchPosition);\n" \ + " //\n" \ + " //\n" \ + " @arrayPush(result, subStr);\n" \ + " //\n" \ + " if (result.length == limit)\n" \ + " return result;\n" \ + "\n" \ + " //\n" \ + " position = endPosition;\n" \ + " //\n" \ + " //\n" \ + " var numberOfCaptures = matches.length > 1 ? matches.length - 1 : 0;\n" \ + "\n" \ + " //\n" \ + " var i = 1;\n" \ + " //\n" \ + " while (i <= numberOfCaptures) {\n" \ + " //\n" \ + " var nextCapture = matches[i];\n" \ + " //\n" \ + " //\n" \ + " @arrayPush(result, nextCapture);\n" \ + " //\n" \ + " if (result.length == limit)\n" \ + " return result;\n" \ + " //\n" \ + " i++;\n" \ + " }\n" \ + " //\n" \ + " matchPosition = position;\n" \ + " }\n" \ + " }\n" \ + " }\n" \ + " //\n" \ + " var remainingStr = @stringSubstring.@call(str, position, size);\n" \ + " //\n" \ + " @arrayPush(result, remainingStr);\n" \ + " //\n" \ + " return result;\n" \ + "})\n" \ +; + +const JSC::ConstructAbility s_onigurumaRegExpPrototypeTestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_onigurumaRegExpPrototypeTestCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeTestCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_onigurumaRegExpPrototypeTestCodeLength = 452; +static const JSC::Intrinsic s_onigurumaRegExpPrototypeTestCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_onigurumaRegExpPrototypeTestCode = + "(function (strArg)\n" \ + "{\n" \ + " \"use strict\";\n" \ + "\n" \ + " var regexp = this;\n" \ + "\n" \ + " if (regexp.test == @Bun.OnigurumaRegExp.prototype.test) {\n" \ + " return regexp.test(strArg);\n" \ + " }\n" \ + "\n" \ + " //\n" \ + " //\n" \ + " if (!@isObject(regexp))\n" \ + " @throwTypeError(\"RegExp.prototype.test requires that |this| be an Object\");\n" \ + "\n" \ + " //\n" \ + " var str = @toString(strArg);\n" \ + "\n" \ + " //\n" \ + " var match = regexp.exec(str);\n" \ + "\n" \ + " //\n" \ + " if (match !== null)\n" \ + " return true;\n" \ + " return false;\n" \ + "})\n" \ +; + + +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ +{\ + JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ + return clientData->builtinFunctions().onigurumaRegExpPrototypeBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().onigurumaRegExpPrototypeBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ +} +WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR + + +} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.h b/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.h new file mode 100644 index 000000000..d8d17d14d --- /dev/null +++ b/src/bun.js/builtins/cpp/OnigurumaRegExpPrototypeBuiltins.h @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2015 Igalia + * Copyright (c) 2015 Igalia S.L. + * Copyright (c) 2015 Igalia. + * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. + * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. + * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. + * Copyright (c) 2022 Codeblog Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#pragma once + +#include <JavaScriptCore/BuiltinUtils.h> +#include <JavaScriptCore/Identifier.h> +#include <JavaScriptCore/JSFunction.h> +#include <JavaScriptCore/UnlinkedFunctionExecutable.h> + +namespace JSC { +class FunctionExecutable; +} + +namespace WebCore { + +/* OnigurumaRegExpPrototype */ +extern const char* const s_onigurumaRegExpPrototypeAdvanceStringIndexCode; +extern const int s_onigurumaRegExpPrototypeAdvanceStringIndexCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeAdvanceStringIndexCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeAdvanceStringIndexCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeAdvanceStringIndexCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeMatchSlowCode; +extern const int s_onigurumaRegExpPrototypeMatchSlowCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchSlowCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchSlowCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchSlowCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeMatchCode; +extern const int s_onigurumaRegExpPrototypeMatchCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeMatchAllCode; +extern const int s_onigurumaRegExpPrototypeMatchAllCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeMatchAllCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeMatchAllCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeMatchAllCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeGetSubstitutionCode; +extern const int s_onigurumaRegExpPrototypeGetSubstitutionCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeGetSubstitutionCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeGetSubstitutionCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeGetSubstitutionCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeReplaceCode; +extern const int s_onigurumaRegExpPrototypeReplaceCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeReplaceCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeReplaceCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeReplaceCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeSearchCode; +extern const int s_onigurumaRegExpPrototypeSearchCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeSearchCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeSearchCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeSearchCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeSplitCode; +extern const int s_onigurumaRegExpPrototypeSplitCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeSplitCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeSplitCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeSplitCodeImplementationVisibility; +extern const char* const s_onigurumaRegExpPrototypeTestCode; +extern const int s_onigurumaRegExpPrototypeTestCodeLength; +extern const JSC::ConstructAbility s_onigurumaRegExpPrototypeTestCodeConstructAbility; +extern const JSC::ConstructorKind s_onigurumaRegExpPrototypeTestCodeConstructorKind; +extern const JSC::ImplementationVisibility s_onigurumaRegExpPrototypeTestCodeImplementationVisibility; + +#define WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_DATA(macro) \ + macro(advanceStringIndex, onigurumaRegExpPrototypeAdvanceStringIndex, 3) \ + macro(matchSlow, onigurumaRegExpPrototypeMatchSlow, 2) \ + macro(match, onigurumaRegExpPrototypeMatch, 1) \ + macro(matchAll, onigurumaRegExpPrototypeMatchAll, 1) \ + macro(getSubstitution, onigurumaRegExpPrototypeGetSubstitution, 6) \ + macro(replace, onigurumaRegExpPrototypeReplace, 2) \ + macro(search, onigurumaRegExpPrototypeSearch, 1) \ + macro(split, onigurumaRegExpPrototypeSplit, 2) \ + macro(test, onigurumaRegExpPrototypeTest, 1) \ + +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_ADVANCESTRINGINDEX 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_MATCHSLOW 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_MATCH 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_MATCHALL 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_GETSUBSTITUTION 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_REPLACE 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_SEARCH 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_SPLIT 1 +#define WEBCORE_BUILTIN_ONIGURUMAREGEXPPROTOTYPE_TEST 1 + +#define WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(macro) \ + macro(onigurumaRegExpPrototypeAdvanceStringIndexCode, advanceStringIndex, ASCIILiteral(), s_onigurumaRegExpPrototypeAdvanceStringIndexCodeLength) \ + macro(onigurumaRegExpPrototypeMatchSlowCode, matchSlow, ASCIILiteral(), s_onigurumaRegExpPrototypeMatchSlowCodeLength) \ + macro(onigurumaRegExpPrototypeMatchCode, match, "[Symbol.match]"_s, s_onigurumaRegExpPrototypeMatchCodeLength) \ + macro(onigurumaRegExpPrototypeMatchAllCode, matchAll, "[Symbol.matchAll]"_s, s_onigurumaRegExpPrototypeMatchAllCodeLength) \ + macro(onigurumaRegExpPrototypeGetSubstitutionCode, getSubstitution, ASCIILiteral(), s_onigurumaRegExpPrototypeGetSubstitutionCodeLength) \ + macro(onigurumaRegExpPrototypeReplaceCode, replace, "[Symbol.replace]"_s, s_onigurumaRegExpPrototypeReplaceCodeLength) \ + macro(onigurumaRegExpPrototypeSearchCode, search, "[Symbol.search]"_s, s_onigurumaRegExpPrototypeSearchCodeLength) \ + macro(onigurumaRegExpPrototypeSplitCode, split, "[Symbol.split]"_s, s_onigurumaRegExpPrototypeSplitCodeLength) \ + macro(onigurumaRegExpPrototypeTestCode, test, ASCIILiteral(), s_onigurumaRegExpPrototypeTestCodeLength) \ + +#define WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_FUNCTION_NAME(macro) \ + macro(advanceStringIndex) \ + macro(getSubstitution) \ + macro(match) \ + macro(matchAll) \ + macro(matchSlow) \ + macro(replace) \ + macro(search) \ + macro(split) \ + macro(test) \ + +#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR + +class OnigurumaRegExpPrototypeBuiltinsWrapper : private JSC::WeakHandleOwner { +public: + explicit OnigurumaRegExpPrototypeBuiltinsWrapper(JSC::VM& vm) + : m_vm(vm) + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { })) + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS + { + } + +#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ + JSC::UnlinkedFunctionExecutable* name##Executable(); \ + const JSC::SourceCode& name##Source() const { return m_##name##Source; } + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +#undef EXPOSE_BUILTIN_EXECUTABLES + + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + + void exportNames(); + +private: + JSC::VM& m_vm; + + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ + JSC::SourceCode m_##name##Source;\ + JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable; + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS + +}; + +#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +inline JSC::UnlinkedFunctionExecutable* OnigurumaRegExpPrototypeBuiltinsWrapper::name##Executable() \ +{\ + if (!m_##name##Executable) {\ + JSC::Identifier executableName = functionName##PublicName();\ + if (overriddenName)\ + executableName = JSC::Identifier::fromString(m_vm, overriddenName);\ + m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ImplementationVisibility, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\ + }\ + return m_##name##Executable.get();\ +} +WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +#undef DEFINE_BUILTIN_EXECUTABLES + +inline void OnigurumaRegExpPrototypeBuiltinsWrapper::exportNames() +{ +#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); + WEBCORE_FOREACH_ONIGURUMAREGEXPPROTOTYPE_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +#undef EXPORT_FUNCTION_NAME +} + +} // namespace WebCore diff --git a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp index 18463bb9d..0a0389ca3 100644 --- a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h index da852b83e..b48359479 100644 --- a/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h +++ b/src/bun.js/builtins/cpp/ProcessObjectBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp index 3b38a593b..e5f3b348e 100644 --- a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h index 2e19b9d21..b3ed9b51a 100644 --- a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp index f1732e48e..087291d8e 100644 --- a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h index 06ee280bf..87afb3da2 100644 --- a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp index 46dcf7f4e..246d7b241 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h index c1d1a4c7f..94969b6e1 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp index 5e0cf16d4..52b56f01a 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h index a5549ad98..91d764366 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp index 03dcd26cb..cd14a15ea 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * @@ -211,106 +212,6 @@ const char* const s_readableStreamReadableStreamToBlobCode = "})\n" \ ; -const JSC::ConstructAbility s_readableStreamReadableStreamToNodeReadableCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; -const JSC::ConstructorKind s_readableStreamReadableStreamToNodeReadableCodeConstructorKind = JSC::ConstructorKind::None; -const JSC::ImplementationVisibility s_readableStreamReadableStreamToNodeReadableCodeImplementationVisibility = JSC::ImplementationVisibility::Private; -const int s_readableStreamReadableStreamToNodeReadableCodeLength = 2476; -static const JSC::Intrinsic s_readableStreamReadableStreamToNodeReadableCodeIntrinsic = JSC::NoIntrinsic; -const char* const s_readableStreamReadableStreamToNodeReadableCode = - "(function (stream) {\n" \ - " \"use strict\";\n" \ - " var {Readable} = @require(\"node:stream\");\n" \ - "\n" \ - " var Prototype = class ReadableNodeStream extends Readable {\n" \ - " #reader;\n" \ - " #stream;\n" \ - " #pushed;\n" \ - " #boundOnData;\n" \ - " #scheduledRead;\n" \ - " constructor(stream) {\n" \ - " super();\n" \ - " this.#stream = stream;\n" \ - " this.#reader = @undefined;\n" \ - " this.#pushed = [];\n" \ - " this.#boundOnData = (result) => this.#onData(result);\n" \ - " this.#scheduledRead = false;\n" \ - " }\n" \ - "\n" \ - " _read(size = 0) {\n" \ - " if (!this.#reader) {\n" \ - " this.#reader = this.#stream.getReader();\n" \ - " }\n" \ - "\n" \ - " const pushed = this.#pushed;\n" \ - " const pending = pushed.length;\n" \ - " for (let i = 0; i < pending; i++) {\n" \ - " if (!this.push(pushed[i])) {\n" \ - " pushed.splice(0, i);\n" \ - " return;\n" \ - " }\n" \ - " }\n" \ - "\n" \ - " this.#scheduleRead();\n" \ - " }\n" \ - "\n" \ - " #handleData(value) {\n" \ - " var i = 0;\n" \ - " const expectedCount = this.#pushed.length;\n" \ - " var pushed = this.#pushed;\n" \ - " try {\n" \ - " for (i; i < expectedCount; i++) {\n" \ - " var item = pushed[i];\n" \ - " if (!this.push(item)) {\n" \ - " return false;\n" \ - " }\n" \ - " }\n" \ - " } catch(e) {\n" \ - " this.error(e);\n" \ - " return false;\n" \ - " } finally {\n" \ - " this.#pushed.splice(0, i);\n" \ - " if (this.#pushed.length > 0) {\n" \ - " this.#pushed.push(...value);\n" \ - " return false;\n" \ - " }\n" \ - "\n" \ - " }\n" \ - "\n" \ - " const valueLength = value.length;\n" \ - " for (i = 0; i < valueLength; i++) {\n" \ - " if (!this.push(value[i])) {\n" \ - " this.#pushed.push(...value.slice(i));\n" \ - " return false;\n" \ - " }\n" \ - " }\n" \ - "\n" \ - " return true;\n" \ - " }\n" \ - "\n" \ - " #onData({done, value}) {\n" \ - " this.#scheduledRead = false;\n" \ - "\n" \ - " if (done) {\n" \ - " this.destroy(@undefined);\n" \ - " return;\n" \ - " }\n" \ - "\n" \ - " if (!this.#handleData(value)) {\n" \ - " return;\n" \ - " }\n" \ - "\n" \ - " this.#scheduleRead();\n" \ - " }\n" \ - "\n" \ - " #scheduleRead() {\n" \ - " if (this.#scheduledRead) return;\n" \ - " this.#scheduledRead = true;\n" \ - " this.#reader.readMany().@then(this.#onData, this.error);\n" \ - " }\n" \ - " };\n" \ - "})\n" \ -; - const JSC::ConstructAbility s_readableStreamConsumeReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_readableStreamConsumeReadableStreamCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_readableStreamConsumeReadableStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Private; diff --git a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h index 503cdfd97..a51da4f44 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * @@ -77,11 +78,6 @@ extern const int s_readableStreamReadableStreamToBlobCodeLength; extern const JSC::ConstructAbility s_readableStreamReadableStreamToBlobCodeConstructAbility; extern const JSC::ConstructorKind s_readableStreamReadableStreamToBlobCodeConstructorKind; extern const JSC::ImplementationVisibility s_readableStreamReadableStreamToBlobCodeImplementationVisibility; -extern const char* const s_readableStreamReadableStreamToNodeReadableCode; -extern const int s_readableStreamReadableStreamToNodeReadableCodeLength; -extern const JSC::ConstructAbility s_readableStreamReadableStreamToNodeReadableCodeConstructAbility; -extern const JSC::ConstructorKind s_readableStreamReadableStreamToNodeReadableCodeConstructorKind; -extern const JSC::ImplementationVisibility s_readableStreamReadableStreamToNodeReadableCodeImplementationVisibility; extern const char* const s_readableStreamConsumeReadableStreamCode; extern const int s_readableStreamConsumeReadableStreamCodeLength; extern const JSC::ConstructAbility s_readableStreamConsumeReadableStreamCodeConstructAbility; @@ -145,7 +141,6 @@ extern const JSC::ImplementationVisibility s_readableStreamLazyAsyncIteratorCode macro(readableStreamToArrayBuffer, readableStreamReadableStreamToArrayBuffer, 1) \ macro(readableStreamToJSON, readableStreamReadableStreamToJSON, 1) \ macro(readableStreamToBlob, readableStreamReadableStreamToBlob, 1) \ - macro(readableStreamToNodeReadable, readableStreamReadableStreamToNodeReadable, 1) \ macro(consumeReadableStream, readableStreamConsumeReadableStream, 3) \ macro(createEmptyReadableStream, readableStreamCreateEmptyReadableStream, 0) \ macro(createNativeReadableStream, readableStreamCreateNativeReadableStream, 3) \ @@ -164,7 +159,6 @@ extern const JSC::ImplementationVisibility s_readableStreamLazyAsyncIteratorCode #define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOARRAYBUFFER 1 #define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOJSON 1 #define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOBLOB 1 -#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTONODEREADABLE 1 #define WEBCORE_BUILTIN_READABLESTREAM_CONSUMEREADABLESTREAM 1 #define WEBCORE_BUILTIN_READABLESTREAM_CREATEEMPTYREADABLESTREAM 1 #define WEBCORE_BUILTIN_READABLESTREAM_CREATENATIVEREADABLESTREAM 1 @@ -184,7 +178,6 @@ extern const JSC::ImplementationVisibility s_readableStreamLazyAsyncIteratorCode macro(readableStreamReadableStreamToArrayBufferCode, readableStreamToArrayBuffer, ASCIILiteral(), s_readableStreamReadableStreamToArrayBufferCodeLength) \ macro(readableStreamReadableStreamToJSONCode, readableStreamToJSON, ASCIILiteral(), s_readableStreamReadableStreamToJSONCodeLength) \ macro(readableStreamReadableStreamToBlobCode, readableStreamToBlob, ASCIILiteral(), s_readableStreamReadableStreamToBlobCodeLength) \ - macro(readableStreamReadableStreamToNodeReadableCode, readableStreamToNodeReadable, ASCIILiteral(), s_readableStreamReadableStreamToNodeReadableCodeLength) \ macro(readableStreamConsumeReadableStreamCode, consumeReadableStream, ASCIILiteral(), s_readableStreamConsumeReadableStreamCodeLength) \ macro(readableStreamCreateEmptyReadableStreamCode, createEmptyReadableStream, ASCIILiteral(), s_readableStreamCreateEmptyReadableStreamCodeLength) \ macro(readableStreamCreateNativeReadableStreamCode, createNativeReadableStream, ASCIILiteral(), s_readableStreamCreateNativeReadableStreamCodeLength) \ @@ -212,7 +205,6 @@ extern const JSC::ImplementationVisibility s_readableStreamLazyAsyncIteratorCode macro(readableStreamToArrayBuffer) \ macro(readableStreamToBlob) \ macro(readableStreamToJSON) \ - macro(readableStreamToNodeReadable) \ macro(readableStreamToText) \ macro(tee) \ macro(values) \ diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp index 185d6cdee..2e9b3f231 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h index 5ae59810a..3dda64a21 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp index b1914d83d..df58f2ab0 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * @@ -93,7 +94,7 @@ const char* const s_readableStreamDefaultReaderCancelCode = const JSC::ConstructAbility s_readableStreamDefaultReaderReadManyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_readableStreamDefaultReaderReadManyCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_readableStreamDefaultReaderReadManyCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_readableStreamDefaultReaderReadManyCodeLength = 4130; +const int s_readableStreamDefaultReaderReadManyCodeLength = 4212; static const JSC::Intrinsic s_readableStreamDefaultReaderReadManyCodeIntrinsic = JSC::NoIntrinsic; const char* const s_readableStreamDefaultReaderReadManyCode = "(function ()\n" \ @@ -120,10 +121,16 @@ const char* const s_readableStreamDefaultReaderReadManyCode = " var queue = @getByIdDirectPrivate(controller, \"queue\");\n" \ " \n" \ " if (!queue) {\n" \ + " //\n" \ + " //\n" \ " return controller.@pull(\n" \ " controller\n" \ " ).@then(\n" \ - " ({done, value}) => (done ? { done: true, value: [], size: 0 } : { value: [value], size: 1, done: false }));\n" \ + " ({done, value}) => (\n" \ + " done ? \n" \ + " { done: true, value: [], size: 0 } : \n" \ + " { value: [value], size: 1, done: false }\n" \ + " ));\n" \ " }\n" \ "\n" \ " const content = queue.content;\n" \ diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h index b883be6b8..b3b9aed91 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp index f1cc09349..8f3caa3a2 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h index a617260be..39b8e8b0d 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h +++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp index 65fe8a753..685fe4507 100644 --- a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h index 089992d77..6e3315a08 100644 --- a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h +++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp index 82319d8b9..bb276fc34 100644 --- a/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp +++ b/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamBuiltins.h index 8547fd350..f299a0659 100644 --- a/src/bun.js/builtins/cpp/TransformStreamBuiltins.h +++ b/src/bun.js/builtins/cpp/TransformStreamBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp index aae09e51d..7a30763d3 100644 --- a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp +++ b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h index a38e0111e..e837fc8c7 100644 --- a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h +++ b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp index 2a0c48fa3..0f09ce57e 100644 --- a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h index 4850ac1fb..90768e1b6 100644 --- a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h +++ b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h index f4fca9b94..e843b7136 100644 --- a/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h +++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h @@ -1,11 +1,14 @@ // clang-format off namespace Zig { class GlobalObject; } +#include "root.h" + /* * Copyright (c) 2015 Igalia * Copyright (c) 2015 Igalia S.L. * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h index 12e9719d3..714be8e4f 100644 --- a/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h +++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * @@ -40,6 +41,7 @@ #include "ImportMetaObjectBuiltins.h" #include "JSBufferConstructorBuiltins.h" #include "JSBufferPrototypeBuiltins.h" +#include "OnigurumaRegExpPrototypeBuiltins.h" #include "ProcessObjectBuiltins.h" #include "ReadableByteStreamControllerBuiltins.h" #include "ReadableByteStreamInternalsBuiltins.h" @@ -69,6 +71,7 @@ public: , m_importMetaObjectBuiltins(m_vm) , m_jsBufferConstructorBuiltins(m_vm) , m_jsBufferPrototypeBuiltins(m_vm) + , m_onigurumaRegExpPrototypeBuiltins(m_vm) , m_processObjectBuiltins(m_vm) , m_readableByteStreamControllerBuiltins(m_vm) , m_readableByteStreamInternalsBuiltins(m_vm) @@ -98,6 +101,7 @@ public: ImportMetaObjectBuiltinsWrapper& importMetaObjectBuiltins() { return m_importMetaObjectBuiltins; } JSBufferConstructorBuiltinsWrapper& jsBufferConstructorBuiltins() { return m_jsBufferConstructorBuiltins; } JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } + OnigurumaRegExpPrototypeBuiltinsWrapper& onigurumaRegExpPrototypeBuiltins() { return m_onigurumaRegExpPrototypeBuiltins; } ProcessObjectBuiltinsWrapper& processObjectBuiltins() { return m_processObjectBuiltins; } ReadableByteStreamControllerBuiltinsWrapper& readableByteStreamControllerBuiltins() { return m_readableByteStreamControllerBuiltins; } ReadableByteStreamInternalsBuiltinsWrapper& readableByteStreamInternalsBuiltins() { return m_readableByteStreamInternalsBuiltins; } @@ -122,6 +126,7 @@ private: ImportMetaObjectBuiltinsWrapper m_importMetaObjectBuiltins; JSBufferConstructorBuiltinsWrapper m_jsBufferConstructorBuiltins; JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; + OnigurumaRegExpPrototypeBuiltinsWrapper m_onigurumaRegExpPrototypeBuiltins; ProcessObjectBuiltinsWrapper m_processObjectBuiltins; ReadableByteStreamControllerBuiltinsWrapper m_readableByteStreamControllerBuiltins; ReadableByteStreamInternalsBuiltinsWrapper m_readableByteStreamInternalsBuiltins; diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp index fed47de16..c4d996494 100644 --- a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp +++ b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h index 41e5a62ab..e8b90012b 100644 --- a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h +++ b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp index 4a2088728..4876aa54a 100644 --- a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp +++ b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h index 70d154bcd..cadcb9840 100644 --- a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h +++ b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp index 73df2027d..e75d0e5dc 100644 --- a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h index f38a4ac60..a869ed60f 100644 --- a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h +++ b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h @@ -4,6 +4,7 @@ * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. + * Copyright (c) 2016, 2018 -2018 Apple Inc. All rights reserved. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * diff --git a/src/bun.js/builtins/js/OnigurumaRegExpPrototype.js b/src/bun.js/builtins/js/OnigurumaRegExpPrototype.js new file mode 100644 index 000000000..e894069f3 --- /dev/null +++ b/src/bun.js/builtins/js/OnigurumaRegExpPrototype.js @@ -0,0 +1,583 @@ +/* + * Copyright (C) 2016-2018 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +@linkTimeConstant +function advanceStringIndex(string, index, unicode) +{ + // This function implements AdvanceStringIndex described in ES6 21.2.5.2.3. + "use strict"; + + if (!unicode) + return index + 1; + + if (index + 1 >= string.length) + return index + 1; + + var first = string.@charCodeAt(index); + if (first < 0xD800 || first > 0xDBFF) + return index + 1; + + var second = string.@charCodeAt(index + 1); + if (second < 0xDC00 || second > 0xDFFF) + return index + 1; + + return index + 2; +} + + +@linkTimeConstant +function matchSlow(regexp, str) +{ + "use strict"; + + if (!regexp.global) + return regexp.exec(str); + + var unicode = regexp.unicode; + regexp.lastIndex = 0; + var resultList = []; + + // FIXME: It would be great to implement a solution similar to what we do in + // RegExpObject::matchGlobal(). It's not clear if this is possible, since this loop has + // effects. https://bugs.webkit.org/show_bug.cgi?id=158145 + var maximumReasonableMatchSize = 100000000; + + while (true) { + var result = regexp.exec(str); + + if (result === null) { + if (resultList.length === 0) + return null; + return resultList; + } + + if (resultList.length > maximumReasonableMatchSize) + @throwOutOfMemoryError(); + + var resultString = @toString(result[0]); + + if (!resultString.length) + regexp.lastIndex = @advanceStringIndex(str, regexp.lastIndex, unicode); + + @arrayPush(resultList, resultString); + } +} + +@overriddenName="[Symbol.match]" +function match(strArg) +{ + "use strict"; + + if (!@isObject(this)) + @throwTypeError("RegExp.prototype.@@match requires that |this| be an Object"); + + var str = @toString(strArg); + + return @matchSlow(this, str); +} + +@overriddenName="[Symbol.matchAll]" +function matchAll(strArg) +{ + "use strict"; + + var regExp = this; + if (!@isObject(regExp)) { + @throwTypeError("RegExp.prototype.@@matchAll requires |this| to be an Object"); + } + + var string = @toString(strArg); + + var Matcher = @speciesConstructor(regExp, @Bun.OnigurumaRegExp); + + var flags = @toString(regExp.flags); + var matcher = new Matcher(regExp.source, flags); + matcher.lastIndex = @toLength(regExp.lastIndex); + + var global = @stringIncludesInternal.@call(flags, "g"); + var fullUnicode = @stringIncludesInternal.@call(flags, "u"); + + var iterator = globalThis.Symbol.iterator; + + var RegExpStringIterator = class RegExpStringIterator { + constructor(regExp, string, global, fullUnicode) + { + + @putByIdDirectPrivate(this, "regExpStringIteratorRegExp", regExp); + @putByIdDirectPrivate(this, "regExpStringIteratorString", string); + @putByIdDirectPrivate(this, "regExpStringIteratorGlobal", global); + @putByIdDirectPrivate(this, "regExpStringIteratorUnicode", fullUnicode); + @putByIdDirectPrivate(this, "regExpStringIteratorDone", false); + } + + next() { + "use strict"; + if (!@isObject(this)) { + @throwTypeError("%RegExpStringIteratorPrototype%.next requires |this| to be an Object"); + } + + var done = @getByIdDirectPrivate(this, "regExpStringIteratorDone"); + if (done === @undefined) { + @throwTypeError("%RegExpStringIteratorPrototype%.next requires |this| to be an RegExp String Iterator instance"); + } + + if (done) { + return { value: @undefined, done: true }; + } + + var regExp = @getByIdDirectPrivate(this, "regExpStringIteratorRegExp"); + var string = @getByIdDirectPrivate(this, "regExpStringIteratorString"); + var global = @getByIdDirectPrivate(this, "regExpStringIteratorGlobal"); + var fullUnicode = @getByIdDirectPrivate(this, "regExpStringIteratorUnicode"); + var match = regExp.exec(string); + if (match === null) { + @putByIdDirectPrivate(this, "regExpStringIteratorDone", true); + return { value: @undefined, done: true }; + } + + if (global) { + var matchStr = @toString(match[0]); + if (matchStr === "") { + var thisIndex = @toLength(regExp.lastIndex); + regExp.lastIndex = @advanceStringIndex(string, thisIndex, fullUnicode); + } + } else + @putByIdDirectPrivate(this, "regExpStringIteratorDone", true); + + return { value: match, done: false }; + } + + [iterator]() { + return this; + } + + }; + + return new RegExpStringIterator(matcher, string, global, fullUnicode); +} + +@linkTimeConstant +function getSubstitution(matched, str, position, captures, namedCaptures, replacement) +{ + "use strict"; + + var matchLength = matched.length; + var stringLength = str.length; + var tailPos = position + matchLength; + var m = captures.length; + var replacementLength = replacement.length; + var result = ""; + var lastStart = 0; + + for (var start = 0; start = @stringIndexOfInternal.@call(replacement, "$", lastStart), start !== -1; lastStart = start) { + if (start - lastStart > 0) + result = result + @stringSubstring.@call(replacement, lastStart, start); + start++; + if (start >= replacementLength) + result = result + "$"; + else { + var ch = replacement[start]; + switch (ch) + { + case "$": + result = result + "$"; + start++; + break; + case "&": + result = result + matched; + start++; + break; + case "`": + if (position > 0) + result = result + @stringSubstring.@call(str, 0, position); + start++; + break; + case "'": + if (tailPos < stringLength) + result = result + @stringSubstring.@call(str, tailPos); + start++; + break; + case "<": + if (namedCaptures !== @undefined) { + var groupNameStartIndex = start + 1; + var groupNameEndIndex = @stringIndexOfInternal.@call(replacement, ">", groupNameStartIndex); + if (groupNameEndIndex !== -1) { + var groupName = @stringSubstring.@call(replacement, groupNameStartIndex, groupNameEndIndex); + var capture = namedCaptures[groupName]; + if (capture !== @undefined) + result = result + @toString(capture); + + start = groupNameEndIndex + 1; + break; + } + } + + result = result + "$<"; + start++; + break; + default: + var chCode = ch.@charCodeAt(0); + if (chCode >= 0x30 && chCode <= 0x39) { + var originalStart = start - 1; + start++; + + var n = chCode - 0x30; + if (n > m) { + result = result + @stringSubstring.@call(replacement, originalStart, start); + break; + } + + if (start < replacementLength) { + var nextChCode = replacement.@charCodeAt(start); + if (nextChCode >= 0x30 && nextChCode <= 0x39) { + var nn = 10 * n + nextChCode - 0x30; + if (nn <= m) { + n = nn; + start++; + } + } + } + + if (n == 0) { + result = result + @stringSubstring.@call(replacement, originalStart, start); + break; + } + + var capture = captures[n - 1]; + if (capture !== @undefined) + result = result + capture; + } else + result = result + "$"; + break; + } + } + } + + return result + @stringSubstring.@call(replacement, lastStart); +} + +@overriddenName="[Symbol.replace]" +function replace(strArg, replace) +{ + "use strict"; + + if (!@isObject(this)) + @throwTypeError("RegExp.prototype.@@replace requires that |this| be an Object"); + + var regexp = this; + + var str = @toString(strArg); + var stringLength = str.length; + var functionalReplace = @isCallable(replace); + + if (!functionalReplace) + replace = @toString(replace); + + var global = regexp.global; + var unicode = false; + + if (global) { + unicode = regexp.unicode; + regexp.lastIndex = 0; + } + + var resultList = []; + var result; + var done = false; + while (!done) { + result = regexp.exec(str); + + if (result === null) + done = true; + else { + @arrayPush(resultList, result); + if (!global) + done = true; + else { + var matchStr = @toString(result[0]); + + if (!matchStr.length) { + var thisIndex = @toLength(regexp.lastIndex); + regexp.lastIndex = @advanceStringIndex(str, thisIndex, unicode); + } + } + } + } + + var accumulatedResult = ""; + var nextSourcePosition = 0; + + for (var i = 0, resultListLength = resultList.length; i < resultListLength; ++i) { + var result = resultList[i]; + var nCaptures = result.length - 1; + if (nCaptures < 0) + nCaptures = 0; + var matched = @toString(result[0]); + var matchLength = matched.length; + var position = @toIntegerOrInfinity(result.index); + position = (position > stringLength) ? stringLength : position; + position = (position < 0) ? 0 : position; + + var captures = []; + for (var n = 1; n <= nCaptures; n++) { + var capN = result[n]; + if (capN !== @undefined) + capN = @toString(capN); + @arrayPush(captures, capN); + } + + var replacement; + var namedCaptures = result.groups; + + if (functionalReplace) { + var replacerArgs = [ matched ]; + for (var j = 0; j < captures.length; j++) + @arrayPush(replacerArgs, captures[j]); + + @arrayPush(replacerArgs, position); + @arrayPush(replacerArgs, str); + + if (namedCaptures !== @undefined) + @arrayPush(replacerArgs, namedCaptures); + + var replValue = replace.@apply(@undefined, replacerArgs); + replacement = @toString(replValue); + } else { + if (namedCaptures !== @undefined) + namedCaptures = @toObject(namedCaptures, "RegExp.prototype[Symbol.replace] requires 'groups' property of a match not be null"); + + replacement = @getSubstitution(matched, str, position, captures, namedCaptures, replace); + } + + if (position >= nextSourcePosition) { + accumulatedResult = accumulatedResult + @stringSubstring.@call(str, nextSourcePosition, position) + replacement; + nextSourcePosition = position + matchLength; + } + } + + if (nextSourcePosition >= stringLength) + return accumulatedResult; + + return accumulatedResult + @stringSubstring.@call(str, nextSourcePosition); +} + +// 21.2.5.9 RegExp.prototype[@@search] (string) +@overriddenName="[Symbol.search]" +function search(strArg) +{ + "use strict"; + + var regexp = this; + + // 1. Let rx be the this value. + // 2. If Type(rx) is not Object, throw a TypeError exception. + if (!@isObject(this)) + @throwTypeError("RegExp.prototype.@@search requires that |this| be an Object"); + + // 3. Let S be ? ToString(string). + var str = @toString(strArg) + + // 4. Let previousLastIndex be ? Get(rx, "lastIndex"). + var previousLastIndex = regexp.lastIndex; + + // 5. If SameValue(previousLastIndex, 0) is false, then + // 5.a. Perform ? Set(rx, "lastIndex", 0, true). + if (!@sameValue(previousLastIndex, 0)) + regexp.lastIndex = 0; + + // 6. Let result be ? RegExpExec(rx, S). + var result = regexp.exec(str); + + // 7. Let currentLastIndex be ? Get(rx, "lastIndex"). + // 8. If SameValue(currentLastIndex, previousLastIndex) is false, then + // 8.a. Perform ? Set(rx, "lastIndex", previousLastIndex, true). + if (!@sameValue(regexp.lastIndex, previousLastIndex)) + regexp.lastIndex = previousLastIndex; + + // 9. If result is null, return -1. + if (result === null) + return -1; + + // 10. Return ? Get(result, "index"). + return result.index; +} + +// ES 21.2.5.11 RegExp.prototype[@@split](string, limit) +@overriddenName="[Symbol.split]" +function split(string, limit) +{ + "use strict"; + + // 1. Let rx be the this value. + // 2. If Type(rx) is not Object, throw a TypeError exception. + if (!@isObject(this)) + @throwTypeError("RegExp.prototype.@@split requires that |this| be an Object"); + var regexp = this; + + // 3. Let S be ? ToString(string). + var str = @toString(string); + + // 4. Let C be ? SpeciesConstructor(rx, %RegExp%). + var speciesConstructor = @speciesConstructor(regexp, @RegExp); + + // 5. Let flags be ? ToString(? Get(rx, "flags")). + var flags = @toString(regexp.flags); + + // 6. If flags contains "u", var unicodeMatching be true. + // 7. Else, let unicodeMatching be false. + var unicodeMatching = @stringIncludesInternal.@call(flags, "u"); + // 8. If flags contains "y", var newFlags be flags. + // 9. Else, let newFlags be the string that is the concatenation of flags and "y". + var newFlags = @stringIncludesInternal.@call(flags, "y") ? flags : flags + "y"; + + // 10. Let splitter be ? Construct(C, « rx, newFlags »). + var splitter = new speciesConstructor(regexp.source, newFlags); + + // We need to check again for RegExp subclasses that will fail the speciesConstructor test + // but can still use the fast path after we invoke the constructor above. + + // 11. Let A be ArrayCreate(0). + // 12. Let lengthA be 0. + var result = []; + + // 13. If limit is undefined, let lim be 2^32-1; else var lim be ? ToUint32(limit). + limit = (limit === @undefined) ? 0xffffffff : limit >>> 0; + + // 16. If lim = 0, return A. + if (!limit) + return result; + + // 14. [Defered from above] Let size be the number of elements in S. + var size = str.length; + + // 17. If size = 0, then + if (!size) { + // a. Let z be ? RegExpExec(splitter, S). + var z = splitter.exec(str); + // b. If z is not null, return A. + if (z !== null) + return result; + // c. Perform ! CreateDataProperty(A, "0", S). + @putByValDirect(result, 0, str); + // d. Return A. + return result; + } + + // 15. [Defered from above] Let p be 0. + var position = 0; + // 18. Let q be p. + var matchPosition = 0; + + // 19. Repeat, while q < size + while (matchPosition < size) { + // a. Perform ? Set(splitter, "lastIndex", q, true). + splitter.lastIndex = matchPosition; + // b. Let z be ? RegExpExec(splitter, S). + var matches = splitter.exec(str); + // c. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). + if (matches === null) + matchPosition = @advanceStringIndex(str, matchPosition, unicodeMatching); + // d. Else z is not null, + else { + // i. Let e be ? ToLength(? Get(splitter, "lastIndex")). + var endPosition = @toLength(splitter.lastIndex); + // ii. Let e be min(e, size). + endPosition = (endPosition <= size) ? endPosition : size; + // iii. If e = p, let q be AdvanceStringIndex(S, q, unicodeMatching). + if (endPosition === position) + matchPosition = @advanceStringIndex(str, matchPosition, unicodeMatching); + // iv. Else e != p, + else { + // 1. Let T be a String value equal to the substring of S consisting of the elements at indices p (inclusive) through q (exclusive). + var subStr = @stringSubstring.@call(str, position, matchPosition); + // 2. Perform ! CreateDataProperty(A, ! ToString(lengthA), T). + // 3. Let lengthA be lengthA + 1. + @arrayPush(result, subStr); + // 4. If lengthA = lim, return A. + if (result.length == limit) + return result; + + // 5. Let p be e. + position = endPosition; + // 6. Let numberOfCaptures be ? ToLength(? Get(z, "length")). + // 7. Let numberOfCaptures be max(numberOfCaptures-1, 0). + var numberOfCaptures = matches.length > 1 ? matches.length - 1 : 0; + + // 8. Let i be 1. + var i = 1; + // 9. Repeat, while i <= numberOfCaptures, + while (i <= numberOfCaptures) { + // a. Let nextCapture be ? Get(z, ! ToString(i)). + var nextCapture = matches[i]; + // b. Perform ! CreateDataProperty(A, ! ToString(lengthA), nextCapture). + // d. Let lengthA be lengthA + 1. + @arrayPush(result, nextCapture); + // e. If lengthA = lim, return A. + if (result.length == limit) + return result; + // c. Let i be i + 1. + i++; + } + // 10. Let q be p. + matchPosition = position; + } + } + } + // 20. Let T be a String value equal to the substring of S consisting of the elements at indices p (inclusive) through size (exclusive). + var remainingStr = @stringSubstring.@call(str, position, size); + // 21. Perform ! CreateDataProperty(A, ! ToString(lengthA), T). + @arrayPush(result, remainingStr); + // 22. Return A. + return result; +} + +// ES 21.2.5.13 RegExp.prototype.test(string) +function test(strArg) +{ + "use strict"; + + var regexp = this; + + if (regexp.test == @Bun.OnigurumaRegExp.prototype.test) { + return regexp.test(strArg); + } + + // 1. Let R be the this value. + // 2. If Type(R) is not Object, throw a TypeError exception. + if (!@isObject(regexp)) + @throwTypeError("RegExp.prototype.test requires that |this| be an Object"); + + // 3. Let string be ? ToString(S). + var str = @toString(strArg); + + // 4. Let match be ? RegExpExec(R, string). + var match = regexp.exec(str); + + // 5. If match is not null, return true; else return false. + if (match !== null) + return true; + return false; +} |