diff options
author | 2022-10-28 18:57:33 -0700 | |
---|---|---|
committer | 2022-10-28 18:57:33 -0700 | |
commit | 280c45c2693546dbc915a0812e855ddda1734739 (patch) | |
tree | 996c27af28d736a39d24fd048e8d5271ae8cbf61 | |
parent | 8bb080fc7c5e59412c32053b629748a7cbb9ffbf (diff) | |
download | bun-280c45c2693546dbc915a0812e855ddda1734739.tar.gz bun-280c45c2693546dbc915a0812e855ddda1734739.tar.zst bun-280c45c2693546dbc915a0812e855ddda1734739.zip |
Upgrade WebKit
-rw-r--r-- | .github/workflows/bun-linux-build.yml | 6 | ||||
-rw-r--r-- | .github/workflows/bun-mac-aarch64.yml | 16 | ||||
-rw-r--r-- | .github/workflows/bun-mac-x64-baseline.yml | 16 | ||||
-rw-r--r-- | .github/workflows/bun-mac-x64.yml | 16 | ||||
-rw-r--r-- | Dockerfile.devcontainer | 2 | ||||
-rw-r--r-- | bench/snippets/array-shift.mjs | 16 | ||||
m--------- | src/bun.js/WebKit | 0 | ||||
-rw-r--r-- | src/bun.js/bindings/BunJSCModule.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/OnigurumaRegExp.cpp | 305 | ||||
-rw-r--r-- | src/bun.js/bindings/headers-cpp.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/headers.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/FetchHeaders.cpp | 15 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/FetchHeaders.h | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/wtf-bindings.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/scripts/class-definitions.ts | 5 | ||||
-rw-r--r-- | src/bun.js/scripts/generate-classes.ts | 145 |
16 files changed, 348 insertions, 205 deletions
diff --git a/.github/workflows/bun-linux-build.yml b/.github/workflows/bun-linux-build.yml index 392b80561..ad03739e7 100644 --- a/.github/workflows/bun-linux-build.yml +++ b/.github/workflows/bun-linux-build.yml @@ -37,21 +37,21 @@ jobs: arch: x86_64 build_arch: amd64 runner: linux-amd64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-linux-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-linux-amd64-lto.tar.gz" webkit_basename: "bun-webkit-linux-amd64-lto" - cpu: westmere tag: linux-x64-baseline arch: x86_64 build_arch: amd64 runner: linux-amd64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-linux-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-linux-amd64-lto.tar.gz" webkit_basename: "bun-webkit-linux-amd64-lto" - cpu: native tag: linux-aarch64 arch: aarch64 build_arch: arm64 runner: linux-arm64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-linux-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-linux-arm64-lto.tar.gz" webkit_basename: "bun-webkit-linux-arm64-lto" steps: diff --git a/.github/workflows/bun-mac-aarch64.yml b/.github/workflows/bun-mac-aarch64.yml index 7686411ca..0546dbccc 100644 --- a/.github/workflows/bun-mac-aarch64.yml +++ b/.github/workflows/bun-mac-aarch64.yml @@ -91,7 +91,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false # - cpu: haswell @@ -100,7 +100,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false # - cpu: westmere @@ -109,7 +109,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true # - cpu: haswell @@ -118,7 +118,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true - cpu: native @@ -126,7 +126,7 @@ jobs: tag: bun-darwin-aarch64 obj: bun-obj-darwin-aarch64 artifact: bun-obj-darwin-aarch64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-arm64-lto.tar.gz" runner: macos-arm64 dependencies: true compile_obj: true @@ -225,7 +225,7 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: haswell # arch: x86_64 # tag: bun-darwin-x64 @@ -233,14 +233,14 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" - cpu: native arch: aarch64 tag: bun-darwin-aarch64 obj: bun-obj-darwin-aarch64 package: bun-darwin-aarch64 artifact: bun-obj-darwin-aarch64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-arm64-lto.tar.gz" runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/bun-mac-x64-baseline.yml b/.github/workflows/bun-mac-x64-baseline.yml index 32095eae3..456738fa0 100644 --- a/.github/workflows/bun-mac-x64-baseline.yml +++ b/.github/workflows/bun-mac-x64-baseline.yml @@ -91,7 +91,7 @@ jobs: obj: bun-obj-darwin-x64-baseline runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" dependencies: true compile_obj: false # - cpu: haswell @@ -100,7 +100,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false - cpu: westmere @@ -109,7 +109,7 @@ jobs: obj: bun-obj-darwin-x64-baseline runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" dependencies: false compile_obj: true # - cpu: haswell @@ -118,7 +118,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true # - cpu: native @@ -126,7 +126,7 @@ jobs: # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # runner: macos-arm64 # dependencies: true # compile_obj: true @@ -219,7 +219,7 @@ jobs: package: bun-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: haswell # arch: x86_64 # tag: bun-darwin-x64 @@ -227,14 +227,14 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: native # arch: aarch64 # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # package: bun-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/bun-mac-x64.yml b/.github/workflows/bun-mac-x64.yml index e9db996b6..a4bd76027 100644 --- a/.github/workflows/bun-mac-x64.yml +++ b/.github/workflows/bun-mac-x64.yml @@ -90,7 +90,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false - cpu: haswell @@ -99,7 +99,7 @@ jobs: obj: bun-obj-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" dependencies: true compile_obj: false # - cpu: westmere @@ -108,7 +108,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true - cpu: haswell @@ -117,7 +117,7 @@ jobs: obj: bun-obj-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" dependencies: false compile_obj: true # - cpu: native @@ -125,7 +125,7 @@ jobs: # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-arm64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-arm64-lto.tar.gz" # runner: macos-arm64 # dependencies: true # compile_obj: true @@ -220,7 +220,7 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" - cpu: haswell arch: x86_64 tag: bun-darwin-x64 @@ -228,14 +228,14 @@ jobs: package: bun-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: native # arch: aarch64 # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # package: bun-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-macos-arm64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-macos-arm64-lto.tar.gz" # runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/Dockerfile.devcontainer b/Dockerfile.devcontainer index 5696eab82..81f666cc8 100644 --- a/Dockerfile.devcontainer +++ b/Dockerfile.devcontainer @@ -88,7 +88,7 @@ RUN cd $GITHUB_WORKSPACE && \ rm zig-linux-$BUILDARCH.zip; RUN cd $GITHUB_WORKSPACE && \ - curl -o bun-webkit-linux-$BUILDARCH.tar.gz -L https://github.com/oven-sh/WebKit/releases/download/oct8/bun-webkit-linux-$BUILDARCH.tar.gz && \ + curl -o bun-webkit-linux-$BUILDARCH.tar.gz -L https://github.com/oven-sh/WebKit/releases/download/oct28/bun-webkit-linux-$BUILDARCH.tar.gz && \ tar -xzf bun-webkit-linux-$BUILDARCH.tar.gz && \ rm bun-webkit-linux-$BUILDARCH.tar.gz && \ cat $WEBKIT_OUT_DIR/include/cmakeconfig.h > /dev/null diff --git a/bench/snippets/array-shift.mjs b/bench/snippets/array-shift.mjs new file mode 100644 index 000000000..2b95bbc9d --- /dev/null +++ b/bench/snippets/array-shift.mjs @@ -0,0 +1,16 @@ +import { bench, run } from "mitata"; + +var myArray = new Array(5); +bench("[1, 2, 3, 4, 5].shift()", () => { + // we do this to prevent constant folding optimizations + if (myArray.length !== 5) myArray.length = 5; + myArray[0] = 1; + myArray[1] = 2; + myArray[2] = 3; + myArray[3] = 4; + myArray[4] = 5; + + myArray.shift(); +}); + +await run(); diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit -Subproject 29179667a6ece649c0ba719135b8a6385ccd8b7 +Subproject 4ffb9be0393081908e18bd6f11eac6e5a5d5b28 diff --git a/src/bun.js/bindings/BunJSCModule.cpp b/src/bun.js/bindings/BunJSCModule.cpp index 39e20d346..92eefd106 100644 --- a/src/bun.js/bindings/BunJSCModule.cpp +++ b/src/bun.js/bindings/BunJSCModule.cpp @@ -70,7 +70,7 @@ JSC_DEFINE_HOST_FUNCTION(functionStartRemoteDebugger, (JSGlobalObject * globalOb return JSC::JSValue::encode(JSC::jsUndefined()); } - globalObject->setRemoteDebuggingEnabled(true); + globalObject->setInspectable(true); auto& server = Inspector::RemoteInspectorServer::singleton(); if (!server.start(reinterpret_cast<const char*>(host), port)) { throwVMError(globalObject, scope, createError(globalObject, "Failed to start server \""_s + host + ":"_s + port + "\". Is port already in use?"_s)); diff --git a/src/bun.js/bindings/OnigurumaRegExp.cpp b/src/bun.js/bindings/OnigurumaRegExp.cpp index 72eaa2b31..3b6066e0f 100644 --- a/src/bun.js/bindings/OnigurumaRegExp.cpp +++ b/src/bun.js/bindings/OnigurumaRegExp.cpp @@ -9,10 +9,10 @@ using namespace WebCore; #include "WebCoreJSClientData.h" -extern "C" EncodedJSValue jsFunctionGetOnigurumaRegExpConstructor(JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName) +extern "C" EncodedJSValue jsFunctionGetOnigurumaRegExpConstructor(JSGlobalObject* lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName) { auto& vm = lexicalGlobalObject->vm(); - Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); return JSValue::encode(globalObject->OnigurumaRegExpConstructor()); } @@ -20,33 +20,42 @@ namespace Zig { static WTF::String to16Bit(ASCIILiteral str) { - return WTF::String::make16BitFrom8BitSource(str.characters8(), str.length()); + UChar* buffer = nullptr; + auto out = WTF::StringImpl::createUninitialized(str.length(), buffer); + WTF::StringImpl::copyCharacters(buffer, str.characters8(), str.length()); + return WTF::String(WTFMove(out)); } -static WTF::String to16Bit(JSC::JSString* str, JSC::JSGlobalObject *globalObject) { +static WTF::String to16Bit(JSC::JSString* str, JSC::JSGlobalObject* globalObject) +{ if (!str->is8Bit() || str->length() == 0) { return str->value(globalObject); } auto value = str->value(globalObject); - return WTF::String::make16BitFrom8BitSource(value.characters8(), value.length()); + auto outStr = WTF::String(value.characters8(), value.length()); + outStr.convertTo16Bit(); + return outStr; } -static WTF::String to16Bit(WTF::String str) { +static WTF::String to16Bit(WTF::String str) +{ if (str.is8Bit()) { - return WTF::String::make16BitFrom8BitSource(str.characters8(), str.length()); + auto out = str.isolatedCopy(); + out.convertTo16Bit(); + return out; } return str; } - -static WTF::String to16Bit(JSValue jsValue, JSC::JSGlobalObject *globalObject, ASCIILiteral defaultValue) { +static WTF::String to16Bit(JSValue jsValue, JSC::JSGlobalObject* globalObject, ASCIILiteral defaultValue) +{ if (!jsValue || jsValue.isUndefinedOrNull()) { - return to16Bit(defaultValue); + return to16Bit(defaultValue); } - auto *jsString = jsValue.toString(globalObject); + auto* jsString = jsValue.toString(globalObject); if (jsString->length() == 0) { return to16Bit(defaultValue); } @@ -54,17 +63,18 @@ static WTF::String to16Bit(JSValue jsValue, JSC::JSGlobalObject *globalObject, return to16Bit(jsString, globalObject); } -static WTF::String extendMultibyteHexCharacters(const WTF::String &string) { +static WTF::String extendMultibyteHexCharacters(const WTF::String& string) +{ WTF::StringBuilder sb; uint32_t length = string.length(); - const UChar *characters = string.characters16(); + const UChar* characters = string.characters16(); bool inCharacterClass = false; for (int i = 0; i < length; i++) { while (characters[i] == '\\') { if (i + 1 < length && characters[i + 1] == 'x') { - if (i + 2 < length && isxdigit(characters[i+ 2])) { - if (i + 3 < length && isxdigit(characters[i+ 3])) { + if (i + 2 < length && isxdigit(characters[i + 2])) { + if (i + 3 < length && isxdigit(characters[i + 3])) { sb.append(string.substring(i, 4)); sb.append("\\x00"_s); i += 4; @@ -88,7 +98,7 @@ static WTF::String extendMultibyteHexCharacters(const WTF::String &string) { if (inCharacterClass) { // we know ']' will be escaped so there isn't a need to scan for the closing bracket if (characters[i] == '[' || characters[i] == ']' || characters[i] == '^' || characters[i] == '-' || characters[i] == ')' || characters[i] == '(') { - if (characters[i- 1] != '\\') { + if (characters[i - 1] != '\\') { // character class intersections not supported, assume end of character class if (characters[i] == ']') { inCharacterClass = false; @@ -100,7 +110,7 @@ static WTF::String extendMultibyteHexCharacters(const WTF::String &string) { } else { if (characters[i] == '[') { if (i - 1 >= 0) { - if (characters[i- 1] != '\\') { + if (characters[i - 1] != '\\') { inCharacterClass = true; } } else { @@ -190,14 +200,11 @@ static inline WTF::String escapedPattern(const WTF::String& pattern, const UChar if (ch == '\n') { result.append('n'); - } - else if (ch == '\r') { + } else if (ch == '\r') { result.append('r'); - } - else if (ch == 0x2028) { + } else if (ch == 0x2028) { result.append("u2028"); - } - else { + } else { result.append("u2029"); } } else @@ -212,8 +219,9 @@ static inline WTF::String escapedPattern(const WTF::String& pattern, const UChar return result.toString(); } -WTF::String sortRegExpFlags(WTF::String flagsString) { - WTF::Vector<UChar> flags = {'d', 'g', 'i', 'm', 's', 'u', 'y'}; +WTF::String sortRegExpFlags(WTF::String flagsString) +{ + WTF::Vector<UChar> flags = { 'd', 'g', 'i', 'm', 's', 'u', 'y' }; WTF::StringBuilder result; for (auto flag : flags) { @@ -225,8 +233,9 @@ WTF::String sortRegExpFlags(WTF::String flagsString) { return result.toString(); } -bool validateRegExpFlags(WTF::StringView flags){ - std::map<char16_t, bool> flagsAllowed = {{'g', false}, {'i', false}, {'m', false}, {'s', false}, {'u', false}, {'y', false}, {'d', false}}; +bool validateRegExpFlags(WTF::StringView flags) +{ + std::map<char16_t, bool> flagsAllowed = { { 'g', false }, { 'i', false }, { 'm', false }, { 's', false }, { 'u', false }, { 'y', false }, { 'd', false } }; for (auto flag : flags.codeUnits()) { auto flagItr = flagsAllowed.find(flag); if (flagItr == flagsAllowed.end() || flagItr->second) { @@ -239,37 +248,35 @@ bool validateRegExpFlags(WTF::StringView flags){ } class OnigurumaRegExpPrototype final : public JSC::JSNonFinalObject { - public: - using Base = JSC::JSNonFinalObject; - - static OnigurumaRegExpPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) - { - OnigurumaRegExpPrototype* ptr = new (NotNull, JSC::allocateCell<OnigurumaRegExpPrototype>(vm)) OnigurumaRegExpPrototype(vm, globalObject, structure); - ptr->finishCreation(vm, globalObject); - return ptr; - } - - DECLARE_INFO; - template<typename CellType, JSC::SubspaceAccess> - static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - return &vm.plainObjectSpace(); - } - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); - } - - private: - OnigurumaRegExpPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) - : Base(vm, structure) - { - } - - void finishCreation(JSC::VM&, JSC::JSGlobalObject*); - }; - +public: + using Base = JSC::JSNonFinalObject; + + static OnigurumaRegExpPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + OnigurumaRegExpPrototype* ptr = new (NotNull, JSC::allocateCell<OnigurumaRegExpPrototype>(vm)) OnigurumaRegExpPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + OnigurumaRegExpPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; class OnigurumaRegEx final : public JSC::JSDestructibleObject { public: @@ -282,9 +289,10 @@ public: return ptr; } - static OnigurumaRegEx* create(JSC::JSGlobalObject* globalObject, WTF::String&& pattern, WTF::String&& flags, regex_t* regExpCode) { - auto *structure = reinterpret_cast<Zig::GlobalObject*>(globalObject)->OnigurumaRegExpStructure(); - auto *object = create(globalObject->vm(), globalObject, structure); + static OnigurumaRegEx* create(JSC::JSGlobalObject* globalObject, WTF::String&& pattern, WTF::String&& flags, regex_t* regExpCode) + { + auto* structure = reinterpret_cast<Zig::GlobalObject*>(globalObject)->OnigurumaRegExpStructure(); + auto* object = create(globalObject->vm(), globalObject, structure); object->m_flagsString = WTFMove(flags); object->m_patternString = WTFMove(pattern); object->m_onigurumaRegExp = regExpCode; @@ -292,27 +300,27 @@ public: return object; } + DECLARE_EXPORT_INFO; + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; - DECLARE_EXPORT_INFO; - template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - if constexpr (mode == JSC::SubspaceAccess::Concurrently) - return nullptr; - return WebCore::subspaceForImpl<OnigurumaRegEx, UseCustomHeapCellType::No>( vm, [](auto& spaces) { return spaces.m_clientSubspaceForOnigurumaRegExp.get(); }, [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForOnigurumaRegExp = WTFMove(space); }, [](auto& spaces) { return spaces.m_subspaceForOnigurumaRegExp.get(); }, [](auto& spaces, auto&& space) { spaces.m_subspaceForOnigurumaRegExp = WTFMove(space); }); - } - static void destroy(JSC::JSCell* cell) { + static void destroy(JSC::JSCell* cell) + { static_cast<OnigurumaRegEx*>(cell)->OnigurumaRegEx::~OnigurumaRegEx(); } - ~OnigurumaRegEx() { + ~OnigurumaRegEx() + { if (m_onigurumaRegExp) { onig_free(m_onigurumaRegExp); } @@ -339,68 +347,67 @@ private: { } - void finishCreation(JSC::VM&) { + void finishCreation(JSC::VM&) + { Base::finishCreation(vm()); - } WTF::String m_patternString = {}; WTF::String m_flagsString = {}; - }; const ClassInfo OnigurumaRegExpConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(OnigurumaRegExpConstructor) }; const ClassInfo OnigurumaRegExpPrototype::s_info = { "Object"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(OnigurumaRegExpPrototype) }; const ClassInfo OnigurumaRegEx::s_info = { "RegExp"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(OnigurumaRegEx) }; -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterGlobal, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterGlobal, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('g'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterDotAll, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterDotAll, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('s'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterHasIndices, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterHasIndices, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('d'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterIgnoreCase, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterIgnoreCase, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('i'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterMultiline, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterMultiline, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('m'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterSticky, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterSticky, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } @@ -408,42 +415,42 @@ JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterSticky, (JSGlobalObject *glob return JSValue::encode(jsBoolean(thisValue->flagsString().contains('y'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterUnicode, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterUnicode, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (UNLIKELY(!thisValue)) { return JSValue::encode(jsUndefined()); } return JSValue::encode(jsBoolean(thisValue->flagsString().contains('u'))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterSource, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterSource, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (!thisValue) return JSValue::encode(jsUndefined()); return JSValue::encode(jsString(globalObject->vm(), escapedPattern(thisValue->patternString(), thisValue->patternString().characters16(), thisValue->patternString().length()))); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterFlags, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterFlags, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); if (!thisValue) return JSValue::encode(jsUndefined()); return JSValue::encode(jsString(globalObject->vm(), thisValue->flagsString())); } -JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterLastIndex, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(onigurumaRegExpProtoGetterLastIndex, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); return JSValue::encode(jsNumber(thisValue->m_lastIndex)); } -JSC_DEFINE_CUSTOM_SETTER(onigurumaRegExpProtoSetterLastIndex, (JSGlobalObject *globalObject, EncodedJSValue encodedThis, EncodedJSValue encodedValue, PropertyName)) +JSC_DEFINE_CUSTOM_SETTER(onigurumaRegExpProtoSetterLastIndex, (JSGlobalObject * globalObject, EncodedJSValue encodedThis, EncodedJSValue encodedValue, PropertyName)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(JSValue::decode(encodedThis)); auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); JSValue value = JSValue::decode(encodedValue); if (!value.isAnyInt()) { @@ -456,14 +463,14 @@ JSC_DEFINE_CUSTOM_SETTER(onigurumaRegExpProtoSetterLastIndex, (JSGlobalObject *g } // compile is deprecated -JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncCompile, (JSGlobalObject *globalObject, JSC::CallFrame *callFrame)) +JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncCompile, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { VM& vm = globalObject->vm(); auto scope = DECLARE_CATCH_SCOPE(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); JSValue thisValue = callFrame->thisValue(); - auto *thisRegExp = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); + auto* thisRegExp = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); if (UNLIKELY(!thisRegExp)) return JSValue::encode(jsUndefined()); @@ -542,8 +549,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncCompile, (JSGlobalObject *globa options, encoding, syntax, - &errorInfo - ); + &errorInfo); if (errorCode != ONIG_NORMAL) { OnigUChar errorBuff[ONIG_MAX_ERROR_MESSAGE_LEN] = { 0 }; @@ -569,12 +575,12 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncCompile, (JSGlobalObject *globa return JSValue::encode(thisRegExp); } -JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncTest, (JSGlobalObject *globalObject, JSC::CallFrame *callFrame)) +JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncTest, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); if (!thisValue) return JSValue::encode(jsUndefined()); @@ -587,7 +593,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncTest, (JSGlobalObject *globalOb WTF::String string = to16Bit(arg, globalObject, ""_s); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); - OnigRegion *region = onig_region_new(); + OnigRegion* region = onig_region_new(); const OnigUChar* end = reinterpret_cast<const OnigUChar*>(string.characters16() + string.length()); const OnigUChar* start = reinterpret_cast<const OnigUChar*>(string.characters16() + thisValue->m_lastIndex); @@ -606,8 +612,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncTest, (JSGlobalObject *globalOb start, range, region, - ONIG_OPTION_DEFAULT - ); + ONIG_OPTION_DEFAULT); if (result < 0) { thisValue->m_lastIndex = 0; @@ -631,13 +636,13 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncTest, (JSGlobalObject *globalOb return JSValue::encode(jsBoolean(true)); } -JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalObject ,JSC::CallFrame *callFrame)) +JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); if (!thisValue) return JSValue::encode(jsUndefined()); @@ -650,7 +655,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb WTF::String string = to16Bit(arg, globalObject, ""_s); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); - OnigRegion *region = onig_region_new(); + OnigRegion* region = onig_region_new(); const OnigUChar* end = reinterpret_cast<const OnigUChar*>(string.characters16() + string.length()); const OnigUChar* start = reinterpret_cast<const OnigUChar*>(string.characters16() + thisValue->m_lastIndex); @@ -663,8 +668,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb start, range, region, - ONIG_OPTION_DEFAULT - ); + ONIG_OPTION_DEFAULT); if (result < 0) { onig_region_free(region, 1); @@ -672,9 +676,9 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb return JSValue::encode(jsNull()); } - JSArray *array = constructEmptyArray(globalObject, nullptr, 0); + JSArray* array = constructEmptyArray(globalObject, nullptr, 0); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); - JSArray *indicesArray = constructEmptyArray(globalObject, nullptr, 0); + JSArray* indicesArray = constructEmptyArray(globalObject, nullptr, 0); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); array->putDirect(vm, vm.propertyNames->index, jsNumber(region->beg[0] / 2)); @@ -683,7 +687,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb for (int i = 0; i < region->num_regs; i++) { size_t outStringLen = (region->end[i] / 2) - (region->beg[i] / 2); - UChar *ptr; + UChar* ptr; WTF::String outString; if (outStringLen > 0) { outString = WTF::String::createUninitialized(static_cast<unsigned int>(outStringLen), ptr); @@ -698,7 +702,7 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb array->putDirectIndex(globalObject, i, jsString(vm, outString)); - JSArray *indices = constructEmptyArray(globalObject, nullptr, 0); + JSArray* indices = constructEmptyArray(globalObject, nullptr, 0); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); indices->putDirectIndex(globalObject, 0, jsNumber(region->beg[i] / 2)); indices->putDirectIndex(globalObject, 1, jsNumber(region->end[i] / 2)); @@ -720,9 +724,9 @@ JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncExec, (JSGlobalObject *globalOb return JSValue::encode(array); } -JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncToString, (JSGlobalObject *globalObject ,JSC::CallFrame *callFrame)) +JSC_DEFINE_HOST_FUNCTION(onigurumaRegExpProtoFuncToString, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - auto *thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); + auto* thisValue = jsDynamicCast<OnigurumaRegEx*>(callFrame->thisValue()); if (!thisValue) return JSValue::encode(jsUndefined()); @@ -742,20 +746,20 @@ void OnigurumaRegExpPrototype::finishCreation(VM& vm, JSGlobalObject* globalObje { Base::finishCreation(vm); ASSERT(inherits(info())); - this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->compile), 2, onigurumaRegExpProtoFuncCompile, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); - this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->exec), 1, onigurumaRegExpProtoFuncExec, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); - this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->toString), 0, onigurumaRegExpProtoFuncToString, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); - this->putDirectCustomAccessor(vm, vm.propertyNames->global, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterGlobal, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->dotAll, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterDotAll, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->hasIndices, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterHasIndices, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->ignoreCase, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterIgnoreCase, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->multiline, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterMultiline, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->sticky, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterSticky, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->unicode, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterUnicode, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->source, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterSource, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->flags, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterFlags, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); - this->putDirectCustomAccessor(vm, vm.propertyNames->lastIndex, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterLastIndex, onigurumaRegExpProtoSetterLastIndex), 0 | PropertyAttribute::CustomAccessor);; - this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->test), 1, onigurumaRegExpProtoFuncTest, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); + this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->compile), 2, onigurumaRegExpProtoFuncCompile, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); + this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->exec), 1, onigurumaRegExpProtoFuncExec, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); + this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->toString), 0, onigurumaRegExpProtoFuncToString, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); + this->putDirectCustomAccessor(vm, vm.propertyNames->global, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterGlobal, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->dotAll, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterDotAll, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->hasIndices, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterHasIndices, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->ignoreCase, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterIgnoreCase, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->multiline, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterMultiline, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->sticky, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterSticky, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->unicode, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterUnicode, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->source, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterSource, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->flags, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterFlags, nullptr), 0 | PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly); + this->putDirectCustomAccessor(vm, vm.propertyNames->lastIndex, JSC::CustomGetterSetter::create(vm, onigurumaRegExpProtoGetterLastIndex, onigurumaRegExpProtoSetterLastIndex), 0 | PropertyAttribute::CustomAccessor); + this->putDirectNativeFunction(vm, globalObject, PropertyName(vm.propertyNames->test), 1, onigurumaRegExpProtoFuncTest, ImplementationVisibility::Public, NoIntrinsic, static_cast<unsigned>(0)); this->putDirectBuiltinFunction(vm, globalObject, vm.propertyNames->matchSymbol, onigurumaRegExpPrototypeMatchCodeGenerator(vm), static_cast<unsigned>(0)); this->putDirectBuiltinFunction(vm, globalObject, vm.propertyNames->matchAllSymbol, onigurumaRegExpPrototypeMatchAllCodeGenerator(vm), static_cast<unsigned>(0)); @@ -770,16 +774,14 @@ JSC::Structure* OnigurumaRegExpConstructor::createClassStructure(JSC::JSGlobalOb return OnigurumaRegEx::createStructure( vm, globalObject, - prototype - ); + prototype); } JSC::JSObject* OnigurumaRegExpConstructor::createPrototype(JSC::JSGlobalObject* globalObject) { return OnigurumaRegExpPrototype::create(globalObject->vm(), globalObject, OnigurumaRegExpPrototype::createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype())); } - -void OnigurumaRegExpConstructor::finishCreation(VM &vm, JSValue prototype) +void OnigurumaRegExpConstructor::finishCreation(VM& vm, JSValue prototype) { Base::finishCreation(vm, 0, "RegExp"_s, PropertyAdditionMode::WithoutStructureTransition); @@ -787,16 +789,16 @@ void OnigurumaRegExpConstructor::finishCreation(VM &vm, JSValue prototype) ASSERT(inherits(info())); } -OnigurumaRegExpConstructor* OnigurumaRegExpConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSValue prototype) +OnigurumaRegExpConstructor* OnigurumaRegExpConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSValue prototype) { OnigurumaRegExpConstructor* ptr = new (NotNull, JSC::allocateCell<OnigurumaRegExpConstructor>(vm)) OnigurumaRegExpConstructor(vm, structure, construct); ptr->finishCreation(vm, prototype); return ptr; } -static JSC::EncodedJSValue constructOrCall(Zig::GlobalObject *globalObject, JSValue arg0, JSValue arg1) +static JSC::EncodedJSValue constructOrCall(Zig::GlobalObject* globalObject, JSValue arg0, JSValue arg1) { - auto &vm = globalObject->vm(); + auto& vm = globalObject->vm(); auto scope = DECLARE_CATCH_SCOPE(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); @@ -808,7 +810,7 @@ static JSC::EncodedJSValue constructOrCall(Zig::GlobalObject *globalObject, JSVa WTF::String flagsString = to16Bit(arg1, globalObject, ""_s); RETURN_IF_EXCEPTION(scope, {}); - if(!validateRegExpFlags(flagsString)) { + if (!validateRegExpFlags(flagsString)) { throwScope.throwException(globalObject, createSyntaxError(globalObject, makeString("Invalid flags supplied to RegExp constructor."_s))); return JSValue::encode({}); } @@ -852,8 +854,7 @@ static JSC::EncodedJSValue constructOrCall(Zig::GlobalObject *globalObject, JSVa options, encoding, syntax, - &errorInfo - ); + &errorInfo); if (errorCode != ONIG_NORMAL) { OnigUChar errorBuff[ONIG_MAX_ERROR_MESSAGE_LEN] = { 0 }; @@ -871,31 +872,29 @@ static JSC::EncodedJSValue constructOrCall(Zig::GlobalObject *globalObject, JSVa RETURN_IF_EXCEPTION(scope, {}); - OnigurumaRegEx *result = OnigurumaRegEx::create(globalObject, WTFMove(patternString), WTFMove(flagsString), onigRegExp); + OnigurumaRegEx* result = OnigurumaRegEx::create(globalObject, WTFMove(patternString), WTFMove(flagsString), onigRegExp); return JSValue::encode(result); } JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES OnigurumaRegExpConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) { - Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); - JSC::VM &vm = globalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + JSC::VM& vm = globalObject->vm(); JSObject* newTarget = asObject(callFrame->newTarget()); auto* constructor = globalObject->OnigurumaRegExpConstructor(); Structure* structure = globalObject->OnigurumaRegExpStructure(); if (constructor != newTarget) { - auto scope = DECLARE_THROW_SCOPE(vm); - - auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>( - // ShadowRealm functions belong to a different global object. - getFunctionRealm(globalObject, newTarget) - ); - RETURN_IF_EXCEPTION(scope, {}); - structure = InternalFunction::createSubclassStructure( - globalObject, - newTarget, - functionGlobalObject->OnigurumaRegExpStructure() - ); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>( + // ShadowRealm functions belong to a different global object. + getFunctionRealm(globalObject, newTarget)); + RETURN_IF_EXCEPTION(scope, {}); + structure = InternalFunction::createSubclassStructure( + globalObject, + newTarget, + functionGlobalObject->OnigurumaRegExpStructure()); } return constructOrCall(globalObject, callFrame->argument(0), callFrame->argument(1)); diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h index 47ca7ef31..559c44d1f 100644 --- a/src/bun.js/bindings/headers-cpp.h +++ b/src/bun.js/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1666335003 +//-- AUTOGENERATED FILE -- 1666999550 // clang-format off #pragma once diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h index d0b3cc938..10052533a 100644 --- a/src/bun.js/bindings/headers.h +++ b/src/bun.js/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format off -//-- AUTOGENERATED FILE -- 1666335003 +//-- AUTOGENERATED FILE -- 1666999550 #pragma once #include <stddef.h> diff --git a/src/bun.js/bindings/webcore/FetchHeaders.cpp b/src/bun.js/bindings/webcore/FetchHeaders.cpp index e852a74d1..713b8a6ac 100644 --- a/src/bun.js/bindings/webcore/FetchHeaders.cpp +++ b/src/bun.js/bindings/webcore/FetchHeaders.cpp @@ -147,6 +147,7 @@ ExceptionOr<void> FetchHeaders::fill(const FetchHeaders& otherHeaders) ExceptionOr<void> FetchHeaders::append(const String& name, const String& value) { + ++m_updateCounter; return appendToHeaderMap(name, value, m_headers, m_guard); } @@ -164,6 +165,7 @@ ExceptionOr<void> FetchHeaders::remove(const String& name) if (m_guard == FetchHeaders::Guard::Response && isForbiddenResponseHeaderName(name)) return {}; + ++m_updateCounter; m_headers.remove(name); if (m_guard == FetchHeaders::Guard::RequestNoCors) @@ -195,6 +197,7 @@ ExceptionOr<void> FetchHeaders::set(const String& name, const String& value) if (!canWriteResult.releaseReturnValue()) return {}; + ++m_updateCounter; m_headers.set(name, normalizedValue); if (m_guard == FetchHeaders::Guard::RequestNoCors) @@ -221,6 +224,14 @@ void FetchHeaders::filterAndFill(const HTTPHeaderMap& headers, Guard guard) std::optional<KeyValuePair<String, String>> FetchHeaders::Iterator::next() { + if (m_keys.isEmpty() || m_updateCounter != m_headers->m_updateCounter) { + m_keys.resize(0); + m_keys.reserveCapacity(m_headers->m_headers.size()); + for (auto& header : m_headers->m_headers) + m_keys.uncheckedAppend(header.key.convertToASCIILowercase()); + std::sort(m_keys.begin(), m_keys.end(), WTF::codePointCompareLessThan); + m_updateCounter = m_headers->m_updateCounter; + } while (m_currentIndex < m_keys.size()) { auto key = m_keys[m_currentIndex++]; auto value = m_headers->m_headers.get(key); @@ -233,10 +244,6 @@ std::optional<KeyValuePair<String, String>> FetchHeaders::Iterator::next() FetchHeaders::Iterator::Iterator(FetchHeaders& headers) : m_headers(headers) { - m_keys.reserveInitialCapacity(headers.m_headers.size()); - for (auto& header : headers.m_headers) - m_keys.uncheckedAppend(header.key.convertToASCIILowercase()); - std::sort(m_keys.begin(), m_keys.end(), WTF::codePointCompareLessThan); } } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/FetchHeaders.h b/src/bun.js/bindings/webcore/FetchHeaders.h index e0fc4a7ff..123833fa0 100644 --- a/src/bun.js/bindings/webcore/FetchHeaders.h +++ b/src/bun.js/bindings/webcore/FetchHeaders.h @@ -81,6 +81,7 @@ public: Ref<FetchHeaders> m_headers; size_t m_currentIndex { 0 }; Vector<String> m_keys; + uint64_t m_updateCounter { 0 }; }; Iterator createIterator() { return Iterator { *this }; } @@ -93,6 +94,8 @@ public: FetchHeaders(Guard, HTTPHeaderMap&&); explicit FetchHeaders(const FetchHeaders&); + uint64_t m_updateCounter { 0 }; + private: Guard m_guard; HTTPHeaderMap m_headers; diff --git a/src/bun.js/bindings/wtf-bindings.cpp b/src/bun.js/bindings/wtf-bindings.cpp index d715f4d45..561c83ffa 100644 --- a/src/bun.js/bindings/wtf-bindings.cpp +++ b/src/bun.js/bindings/wtf-bindings.cpp @@ -3,7 +3,7 @@ extern "C" void WTF__copyLCharsFromUCharSource(LChar* destination, const UChar* source, size_t length) { - WTF::copyLCharsFromUCharSource(destination, source, length); + WTF::StringImpl::copyCharacters(destination, source, length); } extern "C" JSC::EncodedJSValue WTF__toBase64URLStringValue(const uint8_t* bytes, size_t length, JSC::JSGlobalObject* globalObject) diff --git a/src/bun.js/scripts/class-definitions.ts b/src/bun.js/scripts/class-definitions.ts index d9d2fa1d1..8414cf18f 100644 --- a/src/bun.js/scripts/class-definitions.ts +++ b/src/bun.js/scripts/class-definitions.ts @@ -9,7 +9,8 @@ export type Field = return: string; args?: [string, string] | [string, string, string] | [string]; }; - }; + } + | { internal: true }; export interface ClassDefinition { name: string; @@ -21,7 +22,7 @@ export interface ClassDefinition { JSType?: string; noConstructor?: boolean; estimatedSize?: boolean; - isEventEmitter?: boolean; + hasPendingActivity?: boolean; } export function define( diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index 21fba1807..39608dc22 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -246,6 +246,8 @@ export function generateHashTable( const rows = []; for (const name in props) { + if ("internal" in props[name]) continue; + rows.push(propRow(symbolName, typeName, name, props[name], wrapped)); } @@ -549,13 +551,16 @@ ${ function renderCachedFieldsHeader(typeName, klass, proto) { const rows = []; for (const name in klass) { - if ("cache" in klass[name] && klass[name].cache === true) { + if ( + ("cache" in klass[name] && klass[name].cache === true) || + klass[name]?.internal + ) { rows.push(`mutable JSC::WriteBarrier<JSC::Unknown> m_${name};`); } } for (const name in proto) { - if (proto[name]?.cache === true) { + if (proto[name]?.cache === true || klass[name]?.internal) { rows.push(`mutable JSC::WriteBarrier<JSC::Unknown> m_${name};`); } } @@ -702,23 +707,24 @@ JSC_DEFINE_CUSTOM_GETTER(js${typeName}Constructor, (JSGlobalObject * lexicalGlob } for (const name in proto) { - if ("cache" in proto[name]) { + if ("cache" in proto[name] || proto[name]?.internal) { const cacheName = typeof proto[name].cache === "string" ? `m_${proto[name].cache}` : `m_${name}`; - rows.push(` + if ("cache" in proto[name]) { + rows.push(` JSC_DEFINE_CUSTOM_GETTER(${symbolName( - typeName, - name - )}GetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) + typeName, + name + )}GetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { auto& vm = lexicalGlobalObject->vm(); Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); ${className(typeName)}* thisObject = jsCast<${className( - typeName - )}*>(JSValue::decode(thisValue)); + typeName + )}*>(JSValue::decode(thisValue)); JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); if (JSValue cachedValue = thisObject->${cacheName}.get()) @@ -733,7 +739,10 @@ JSC_DEFINE_CUSTOM_GETTER(${symbolName( RETURN_IF_EXCEPTION(throwScope, {}); thisObject->${cacheName}.set(vm, thisObject, result); RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); -} +}`); + } + rows.push(` + extern "C" void ${symbolName( typeName, name @@ -745,6 +754,18 @@ extern "C" void ${symbolName( )}*>(JSValue::decode(thisValue)); thisObject->${cacheName}.set(vm, thisObject, JSValue::decode(value)); } + +extern "C" EncodedJSValue ${symbolName( + typeName, + name + )}GetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<${className( + typeName + )}*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->${cacheName}.get()); +} + `); } else if ( "getter" in proto[name] || @@ -847,6 +868,40 @@ function generateClassHeader(typeName, obj: ClassDefinition) { ? "static size_t estimatedSize(JSCell* cell, VM& vm);" : ""; + var weakOwner = ""; + var weakInit = ""; + + if (obj.hasPendingActivity) { + weakOwner = ` + JSC::Weak<${name}> m_weakThis; + bool internalHasPendingActivity(); + bool hasPendingActivity() { + if (!m_ctx) + return false; + + return this->internalHasPendingActivity(); + } + + class Owner final : public JSC::WeakHandleOwner { + public: + bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void* context, JSC::AbstractSlotVisitor&, const char**) final + { + auto* controller = JSC::jsCast<${name}*>(handle.slot()->asCell()); + return controller->hasPendingActivity(); + } + void finalize(JSC::Handle<JSC::Unknown>, void* context) final {} + }; + + static JSC::WeakHandleOwner* getOwner() + { + static NeverDestroyed<Owner> m_owner; + return &m_owner.get(); + } + `; + weakInit = ` + m_weakThis = JSC::Weak<${name}>(vm, this, getOwner()); +`; + } return ` class ${name} final : public JSC::JSDestructibleObject { public: @@ -901,10 +956,13 @@ function generateClassHeader(typeName, obj: ClassDefinition) { : Base(vm, structure) { m_ctx = sinkPtr; + ${weakInit.trim()} } void finishCreation(JSC::VM&); + ${weakOwner} + ${DECLARE_VISIT_CHILDREN} ${renderCachedFieldsHeader(typeName, klass, proto)} @@ -913,14 +971,24 @@ function generateClassHeader(typeName, obj: ClassDefinition) { } function generateClassImpl(typeName, obj: ClassDefinition) { - const { klass: fields, finalize, proto, construct, estimatedSize } = obj; + const { + klass: fields, + finalize, + proto, + construct, + estimatedSize, + hasPendingActivity = false, + } = obj; const name = className(typeName); const DEFINE_VISIT_CHILDREN_LIST = [ ...Object.entries(fields), ...Object.entries(proto), ] - .filter(([name, { cache = false }]) => cache === true) + .filter( + ([name, { cache = false, internal = false }]) => + (cache || internal) === true + ) .map(([name]) => ` visitor.append(thisObject->m_${name});`) .join("\n"); @@ -955,6 +1023,15 @@ DEFINE_VISIT_CHILDREN(${name}); var output = ``; + if (hasPendingActivity) { + output += ` + extern "C" bool ${symbolName(typeName, "hasPendingActivity")}(void* ptr); + ${name}::internalHasPendingActivity() { + return ${symbolName(typeName, "hasPendingActivity")}(m_ctx); + } +`; + } + if (finalize) { output += ` ${name}::~${name}() @@ -989,6 +1066,7 @@ void ${name}::finishCreation(VM& vm) ASSERT(inherits(info())); } + ${name}* ${name}::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) { ${name}* ptr = new (NotNull, JSC::allocateCell<${name}>(vm)) ${name}(vm, structure, ctx); ptr->finishCreation(vm); @@ -1079,6 +1157,7 @@ function generateZig( finalize, noConstructor, estimatedSize, + hasPendingActivity = false, } = {} as ClassDefinition ) { const exports = new Map<string, string>(); @@ -1095,6 +1174,13 @@ function generateZig( exports.set(`estimatedSize`, symbolName(typeName, "estimatedSize")); } + if (hasPendingActivity) { + exports.set( + "hasPendingActivity", + symbolName(typeName, "hasPendingActivity") + ); + } + Object.values(klass).map((a) => appendSymbols(exports, (name) => classSymbolName(typeName, name), a) ); @@ -1103,15 +1189,23 @@ function generateZig( ); const externs = Object.entries(proto) - .filter(([name, { cache }]) => cache && typeof cache !== "string") + .filter( + ([name, { cache, internal }]) => + (cache && typeof cache !== "string") || internal + ) .map( ([name, { cache }]) => `extern fn ${protoSymbolName( typeName, name )}SetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn ${protoSymbolName( + typeName, + name + )}GetCachedValue(JSC.JSValue) JSC.JSValue; - /// Set the cached value for ${name} on ${typeName} + /// \`${typeName}.${name}\` setter /// This value will be visited by the garbage collector. pub fn ${name}SetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { JSC.markBinding(@src()); @@ -1120,6 +1214,20 @@ function generateZig( name )}SetCachedValue(thisValue, globalObject, value); } + + /// \`${typeName}.${name}\` getter + /// This value will be visited by the garbage collector. + pub fn ${name}GetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = ${protoSymbolName( + typeName, + name + )}GetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } `.trim() + "\n" ) .join("\n"); @@ -1281,6 +1389,15 @@ pub const ${className(typeName)} = struct { return ${symbolName(typeName, "dangerouslySetPtr")}(value, ptr); } + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *${typeName}, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(${symbolName( + typeName, + "dangerouslySetPtr" + )}(value, null)); + } + extern fn ${symbolName(typeName, "fromJS")}(JSC.JSValue) ?*${typeName}; extern fn ${symbolName( typeName, |