aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-18 19:06:29 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-18 19:06:29 -0700
commite3c2a95e5ff4e6c6b63839f4773cc3f5aeadddc8 (patch)
treeec2e43f3a33bdd784473022b00121f4c597c8e09 /src/bun.js
parente45ddc086fe6b3e7a32aa45607f5e3d570998137 (diff)
downloadbun-e3c2a95e5ff4e6c6b63839f4773cc3f5aeadddc8.tar.gz
bun-e3c2a95e5ff4e6c6b63839f4773cc3f5aeadddc8.tar.zst
bun-e3c2a95e5ff4e6c6b63839f4773cc3f5aeadddc8.zip
Faster TextDecoder
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/bun.zig1
-rw-r--r--src/bun.js/api/crypto.classes.ts1
-rw-r--r--src/bun.js/base.zig12
-rw-r--r--src/bun.js/bindings/JSSink.cpp2
-rw-r--r--src/bun.js/bindings/JSSink.h2
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h4
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h4
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h8
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h10
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.cpp185
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.h52
-rw-r--r--src/bun.js/bindings/ZigGeneratedCode.cpp102
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp14
-rw-r--r--src/bun.js/bindings/bindings.zig16
-rw-r--r--src/bun.js/bindings/generated_classes.zig92
-rw-r--r--src/bun.js/bindings/generated_classes_list.zig2
-rw-r--r--src/bun.js/bindings/headers.h2
-rw-r--r--src/bun.js/bindings/shimmer.zig3
-rw-r--r--src/bun.js/javascript.zig3
-rw-r--r--src/bun.js/node/node_fs.zig2
-rw-r--r--src/bun.js/scripts/generate-classes.ts30
-rw-r--r--src/bun.js/typescript.zig1
-rw-r--r--src/bun.js/webcore/encoding.classes.ts25
-rw-r--r--src/bun.js/webcore/encoding.zig195
24 files changed, 399 insertions, 369 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 0f578fb49..9ddf309cc 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -1451,7 +1451,6 @@ pub const Crypto = struct {
pub const SHA384 = CryptoHasher(Hashers.SHA384, "SHA384");
pub const SHA256 = CryptoHasher(Hashers.SHA256, "SHA256");
pub const SHA512_256 = CryptoHasher(Hashers.SHA512_256, "SHA512_256");
- pub const MD5_SHA1 = CryptoHasher(Hashers.MD5_SHA1, "MD5_SHA1");
};
pub fn nanoseconds(
diff --git a/src/bun.js/api/crypto.classes.ts b/src/bun.js/api/crypto.classes.ts
index 20e24c342..212e991a0 100644
--- a/src/bun.js/api/crypto.classes.ts
+++ b/src/bun.js/api/crypto.classes.ts
@@ -9,7 +9,6 @@ const names = [
"SHA384",
"SHA256",
"SHA512_256",
- "MD5_SHA1",
];
export default names.map((name) => {
return define({
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index 17e0232da..fac45dc59 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -2805,9 +2805,7 @@ pub const JSPrivateDataPtr = TaggedPointerUnion(.{
HTMLRewriter,
JSNode,
LazyPropertiesObject,
- MD4,
- MD5_SHA1,
- MD5,
+
ModuleNamespace,
NodeFS,
Request,
@@ -2815,16 +2813,10 @@ pub const JSPrivateDataPtr = TaggedPointerUnion(.{
Response,
Router,
Server,
- SHA1,
- SHA224,
- SHA256,
- SHA384,
- SHA512_256,
- SHA512,
+
SSLServer,
Stats,
TextChunk,
- TextDecoder,
TimeoutTask,
Transpiler,
FFI,
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp
index 87cdae923..fc77113ac 100644
--- a/src/bun.js/bindings/JSSink.cpp
+++ b/src/bun.js/bindings/JSSink.cpp
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2022-08-18T01:38:52.472Z
+// Generated by 'make generate-sink' at 2022-08-19T01:36:01.093Z
// To regenerate this file, run:
//
// make generate-sink
diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h
index 56a0d584a..32c0ff021 100644
--- a/src/bun.js/bindings/JSSink.h
+++ b/src/bun.js/bindings/JSSink.h
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2022-08-18T01:38:52.471Z
+// Generated by 'make generate-sink' at 2022-08-19T01:36:01.092Z
//
#pragma once
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
index 27e266f62..03282a16a 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
@@ -6,7 +6,7 @@ std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA224Constructor;std:
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA512Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA384;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA384Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA256;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA256Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA512_256;
-std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA512_256Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForMD5_SHA1;
-std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForMD5_SHA1Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequest;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForSHA512_256Constructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForTextDecoder;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForTextDecoderConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequest;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequestConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponse;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponseConstructor; \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
index 8af2fc114..0cbf0776c 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
@@ -6,7 +6,7 @@ std::unique_ptr<IsoSubspace> m_subspaceForSHA224Constructor;std::unique_ptr<IsoS
std::unique_ptr<IsoSubspace> m_subspaceForSHA512Constructor;std::unique_ptr<IsoSubspace> m_subspaceForSHA384;
std::unique_ptr<IsoSubspace> m_subspaceForSHA384Constructor;std::unique_ptr<IsoSubspace> m_subspaceForSHA256;
std::unique_ptr<IsoSubspace> m_subspaceForSHA256Constructor;std::unique_ptr<IsoSubspace> m_subspaceForSHA512_256;
-std::unique_ptr<IsoSubspace> m_subspaceForSHA512_256Constructor;std::unique_ptr<IsoSubspace> m_subspaceForMD5_SHA1;
-std::unique_ptr<IsoSubspace> m_subspaceForMD5_SHA1Constructor;std::unique_ptr<IsoSubspace> m_subspaceForRequest;
+std::unique_ptr<IsoSubspace> m_subspaceForSHA512_256Constructor;std::unique_ptr<IsoSubspace> m_subspaceForTextDecoder;
+std::unique_ptr<IsoSubspace> m_subspaceForTextDecoderConstructor;std::unique_ptr<IsoSubspace> m_subspaceForRequest;
std::unique_ptr<IsoSubspace> m_subspaceForRequestConstructor;std::unique_ptr<IsoSubspace> m_subspaceForResponse;
std::unique_ptr<IsoSubspace> m_subspaceForResponseConstructor; \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
index 4a3b95f74..da5480541 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
@@ -30,10 +30,10 @@ JSC::Structure* JSSHA512_256Structure() { return m_JSSHA512_256.getInitializedOn
JSC::JSObject* JSSHA512_256Constructor() { return m_JSSHA512_256.constructorInitializedOnMainThread(this); }
JSC::JSValue JSSHA512_256Prototype() { return m_JSSHA512_256.prototypeInitializedOnMainThread(this); }
JSC::LazyClassStructure m_JSSHA512_256;
-JSC::Structure* JSMD5_SHA1Structure() { return m_JSMD5_SHA1.getInitializedOnMainThread(this); }
- JSC::JSObject* JSMD5_SHA1Constructor() { return m_JSMD5_SHA1.constructorInitializedOnMainThread(this); }
- JSC::JSValue JSMD5_SHA1Prototype() { return m_JSMD5_SHA1.prototypeInitializedOnMainThread(this); }
- JSC::LazyClassStructure m_JSMD5_SHA1;
+JSC::Structure* JSTextDecoderStructure() { return m_JSTextDecoder.getInitializedOnMainThread(this); }
+ JSC::JSObject* JSTextDecoderConstructor() { return m_JSTextDecoder.constructorInitializedOnMainThread(this); }
+ JSC::JSValue JSTextDecoderPrototype() { return m_JSTextDecoder.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_JSTextDecoder;
JSC::Structure* JSRequestStructure() { return m_JSRequest.getInitializedOnMainThread(this); }
JSC::JSObject* JSRequestConstructor() { return m_JSRequest.constructorInitializedOnMainThread(this); }
JSC::JSValue JSRequestPrototype() { return m_JSRequest.prototypeInitializedOnMainThread(this); }
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
index d2ec2ccae..eca66eb15 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
@@ -47,11 +47,11 @@ void GlobalObject::initGeneratedLazyClasses() {
init.setStructure(WebCore::JSSHA512_256::createStructure(init.vm, init.global, init.prototype));
init.setConstructor(WebCore::JSSHA512_256Constructor::create(init.vm, init.global, WebCore::JSSHA512_256Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA512_256Prototype*>(init.prototype)));
});
- m_JSMD5_SHA1.initLater(
+ m_JSTextDecoder.initLater(
[](LazyClassStructure::Initializer& init) {
- init.setPrototype(WebCore::JSMD5_SHA1::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
- init.setStructure(WebCore::JSMD5_SHA1::createStructure(init.vm, init.global, init.prototype));
- init.setConstructor(WebCore::JSMD5_SHA1Constructor::create(init.vm, init.global, WebCore::JSMD5_SHA1Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSMD5_SHA1Prototype*>(init.prototype)));
+ init.setPrototype(WebCore::JSTextDecoder::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::JSTextDecoder::createStructure(init.vm, init.global, init.prototype));
+ init.setConstructor(WebCore::JSTextDecoderConstructor::create(init.vm, init.global, WebCore::JSTextDecoderConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSTextDecoderPrototype*>(init.prototype)));
});
m_JSRequest.initLater(
[](LazyClassStructure::Initializer& init) {
@@ -77,7 +77,7 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor&
thisObject->m_JSSHA384.visit(visitor);
thisObject->m_JSSHA256.visit(visitor);
thisObject->m_JSSHA512_256.visit(visitor);
- thisObject->m_JSMD5_SHA1.visit(visitor);
+ thisObject->m_JSTextDecoder.visit(visitor);
thisObject->m_JSRequest.visit(visitor);
thisObject->m_JSResponse.visit(visitor);
} \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp
index 58e300890..068b6a92e 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.cpp
+++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp
@@ -1879,68 +1879,55 @@ void JSSHA512_256::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
JSObject* JSSHA512_256::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
{
return JSSHA512_256Prototype::create(vm, globalObject, JSSHA512_256Prototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
-}extern "C" void* MD5_SHA1Class__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
-JSC_DECLARE_CUSTOM_GETTER(jsMD5_SHA1Constructor);
-extern "C" void MD5_SHA1Class__finalize(void*);
+}extern "C" void* TextDecoderClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+JSC_DECLARE_CUSTOM_GETTER(jsTextDecoderConstructor);
+extern "C" void TextDecoderClass__finalize(void*);
-extern "C" JSC::EncodedJSValue MD5_SHA1Prototype__getByteLength(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
-JSC_DECLARE_CUSTOM_GETTER(MD5_SHA1Prototype__byteLengthGetterWrap);
+extern "C" EncodedJSValue TextDecoderPrototype__decode(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TextDecoderPrototype__decodeCallback);
-extern "C" EncodedJSValue MD5_SHA1Prototype__digest(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
-JSC_DECLARE_HOST_FUNCTION(MD5_SHA1Prototype__digestCallback);
+extern "C" JSC::EncodedJSValue TextDecoderPrototype__getEncoding(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(TextDecoderPrototype__encodingGetterWrap);
-extern "C" EncodedJSValue MD5_SHA1Prototype__update(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
-JSC_DECLARE_HOST_FUNCTION(MD5_SHA1Prototype__updateCallback);
+extern "C" JSC::EncodedJSValue TextDecoderPrototype__getFatal(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(TextDecoderPrototype__fatalGetterWrap);
-STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSMD5_SHA1Prototype, JSMD5_SHA1Prototype::Base);
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTextDecoderPrototype, JSTextDecoderPrototype::Base);
- static const HashTableValue JSMD5_SHA1PrototypeTableValues[] = {
-{ "byteLength"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(MD5_SHA1Prototype__byteLengthGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
-{ "digest"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(MD5_SHA1Prototype__digestCallback), (intptr_t)(0) } } ,
-{ "update"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(MD5_SHA1Prototype__updateCallback), (intptr_t)(0) } }
+ static const HashTableValue JSTextDecoderPrototypeTableValues[] = {
+{ "decode"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(TextDecoderPrototype__decodeCallback), (intptr_t)(1) } } ,
+{ "encoding"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(TextDecoderPrototype__encodingGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "fatal"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(TextDecoderPrototype__fatalGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }
};
-const ClassInfo JSMD5_SHA1Prototype::s_info = { "MD5_SHA1"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMD5_SHA1Prototype) };
+const ClassInfo JSTextDecoderPrototype::s_info = { "TextDecoder"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoderPrototype) };
-JSC_DEFINE_CUSTOM_GETTER(jsMD5_SHA1Constructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
+JSC_DEFINE_CUSTOM_GETTER(jsTextDecoderConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
- auto* prototype = jsDynamicCast<JSMD5_SHA1Prototype*>(JSValue::decode(thisValue));
+ auto* prototype = jsDynamicCast<JSTextDecoderPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
- return JSValue::encode(globalObject->JSMD5_SHA1Constructor());
+ return JSValue::encode(globalObject->JSTextDecoderConstructor());
}
-JSC_DEFINE_CUSTOM_GETTER(MD5_SHA1Prototype__byteLengthGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
-{
- auto& vm = lexicalGlobalObject->vm();
- Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
- auto throwScope = DECLARE_THROW_SCOPE(vm);
- JSMD5_SHA1* thisObject = jsCast<JSMD5_SHA1*>(JSValue::decode(thisValue));
- JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
- JSC::EncodedJSValue result = MD5_SHA1Prototype__getByteLength(thisObject->wrapped(), globalObject);
- RETURN_IF_EXCEPTION(throwScope, {});
- RELEASE_AND_RETURN(throwScope, result);
-}
-
-
-JSC_DEFINE_HOST_FUNCTION(MD5_SHA1Prototype__digestCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+JSC_DEFINE_HOST_FUNCTION(TextDecoderPrototype__decodeCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
- JSMD5_SHA1* thisObject = jsDynamicCast<JSMD5_SHA1*>(callFrame->thisValue());
+ JSTextDecoder* thisObject = jsDynamicCast<JSTextDecoder*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -1949,64 +1936,71 @@ JSC_DEFINE_HOST_FUNCTION(MD5_SHA1Prototype__digestCallback, (JSGlobalObject * le
JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
- return MD5_SHA1Prototype__digest(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+ return TextDecoderPrototype__decode(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
-JSC_DEFINE_HOST_FUNCTION(MD5_SHA1Prototype__updateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+JSC_DEFINE_CUSTOM_GETTER(TextDecoderPrototype__encodingGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
{
auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSTextDecoder* thisObject = jsCast<JSTextDecoder*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_encoding.get())
+ return JSValue::encode(cachedValue);
- JSMD5_SHA1* thisObject = jsDynamicCast<JSMD5_SHA1*>(callFrame->thisValue());
+ JSC::JSValue result = JSC::JSValue::decode(
+ TextDecoderPrototype__getEncoding(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_encoding.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
- if (UNLIKELY(!thisObject)) {
- auto throwScope = DECLARE_THROW_SCOPE(vm);
- return throwVMTypeError(lexicalGlobalObject, throwScope);
- }
+JSC_DEFINE_CUSTOM_GETTER(TextDecoderPrototype__fatalGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSTextDecoder* thisObject = jsCast<JSTextDecoder*>(JSValue::decode(thisValue));
JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
-
- return MD5_SHA1Prototype__update(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+ JSC::EncodedJSValue result = TextDecoderPrototype__getFatal(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
}
+
-
-void JSMD5_SHA1Prototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+void JSTextDecoderPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
- reifyStaticProperties(vm, JSMD5_SHA1::info(), JSMD5_SHA1PrototypeTableValues, *this);
+ reifyStaticProperties(vm, JSTextDecoder::info(), JSTextDecoderPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
-extern "C" JSC_DECLARE_CUSTOM_GETTER(MD5_SHA1Class__getByteLengthStatic);
-extern "C" JSC_DECLARE_HOST_FUNCTION(MD5_SHA1Class__hash);
-
- static const HashTableValue JSMD5_SHA1ConstructorTableValues[] = {
-{ "byteLength"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(MD5_SHA1Class__getByteLengthStatic), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
-{ "hash"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(MD5_SHA1Class__hash), (intptr_t)(2) } }
- };
-
-
-void JSMD5_SHA1Constructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSMD5_SHA1Prototype* prototype)
+void JSTextDecoderConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSTextDecoderPrototype* prototype)
{
- Base::finishCreation(vm, 0, "MD5_SHA1"_s, PropertyAdditionMode::WithoutStructureTransition);
- reifyStaticProperties(vm, &JSMD5_SHA1Constructor::s_info, JSMD5_SHA1ConstructorTableValues, *this);
+ Base::finishCreation(vm, 0, "TextDecoder"_s, PropertyAdditionMode::WithoutStructureTransition);
+
putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
ASSERT(inherits(info()));
}
-JSMD5_SHA1Constructor* JSMD5_SHA1Constructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSMD5_SHA1Prototype* prototype) {
- JSMD5_SHA1Constructor* ptr = new (NotNull, JSC::allocateCell<JSMD5_SHA1Constructor>(vm)) JSMD5_SHA1Constructor(vm, structure, construct);
+JSTextDecoderConstructor* JSTextDecoderConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSTextDecoderPrototype* prototype) {
+ JSTextDecoderConstructor* ptr = new (NotNull, JSC::allocateCell<JSTextDecoderConstructor>(vm)) JSTextDecoderConstructor(vm, structure, construct);
ptr->finishCreation(vm, globalObject, prototype);
return ptr;
}
-JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSMD5_SHA1Constructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSTextDecoderConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
{
Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
JSC::VM &vm = globalObject->vm();
JSObject* newTarget = asObject(callFrame->newTarget());
- auto* constructor = globalObject->JSMD5_SHA1Constructor();
- Structure* structure = globalObject->JSMD5_SHA1Structure();
+ auto* constructor = globalObject->JSTextDecoderConstructor();
+ Structure* structure = globalObject->JSTextDecoderStructure();
if (constructor != newTarget) {
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -2018,76 +2012,76 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSMD5_SHA1Constructor::construct(JS
structure = InternalFunction::createSubclassStructure(
globalObject,
newTarget,
- functionGlobalObject->JSMD5_SHA1Structure()
+ functionGlobalObject->JSTextDecoderStructure()
);
}
- void* ptr = MD5_SHA1Class__construct(globalObject, callFrame);
+ void* ptr = TextDecoderClass__construct(globalObject, callFrame);
if (UNLIKELY(!ptr)) {
return JSValue::encode(JSC::jsUndefined());
}
- JSMD5_SHA1* instance = JSMD5_SHA1::create(vm, globalObject, structure, ptr);
+ JSTextDecoder* instance = JSTextDecoder::create(vm, globalObject, structure, ptr);
return JSValue::encode(instance);
}
-extern "C" EncodedJSValue MD5_SHA1__create(Zig::GlobalObject* globalObject, void* ptr) {
+extern "C" EncodedJSValue TextDecoder__create(Zig::GlobalObject* globalObject, void* ptr) {
auto &vm = globalObject->vm();
- JSC::Structure* structure = globalObject->JSMD5_SHA1Structure();
- JSMD5_SHA1* instance = JSMD5_SHA1::create(vm, globalObject, structure, ptr);
+ JSC::Structure* structure = globalObject->JSTextDecoderStructure();
+ JSTextDecoder* instance = JSTextDecoder::create(vm, globalObject, structure, ptr);
return JSValue::encode(instance);
}
-void JSMD5_SHA1Constructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSMD5_SHA1Prototype* prototype)
+void JSTextDecoderConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSTextDecoderPrototype* prototype)
{
}
-const ClassInfo JSMD5_SHA1Constructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMD5_SHA1Constructor) };
+const ClassInfo JSTextDecoderConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoderConstructor) };
-extern "C" EncodedJSValue MD5_SHA1__getConstructor(Zig::GlobalObject* globalObject) {
- return JSValue::encode(globalObject->JSMD5_SHA1Constructor());
+extern "C" EncodedJSValue TextDecoder__getConstructor(Zig::GlobalObject* globalObject) {
+ return JSValue::encode(globalObject->JSTextDecoderConstructor());
}
-JSMD5_SHA1::~JSMD5_SHA1()
+JSTextDecoder::~JSTextDecoder()
{
if (m_ctx) {
- MD5_SHA1Class__finalize(m_ctx);
+ TextDecoderClass__finalize(m_ctx);
}
}
-void JSMD5_SHA1::destroy(JSCell* cell)
+void JSTextDecoder::destroy(JSCell* cell)
{
- static_cast<JSMD5_SHA1*>(cell)->JSMD5_SHA1::~JSMD5_SHA1();
+ static_cast<JSTextDecoder*>(cell)->JSTextDecoder::~JSTextDecoder();
}
-const ClassInfo JSMD5_SHA1::s_info = { "MD5_SHA1"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMD5_SHA1) };
+const ClassInfo JSTextDecoder::s_info = { "TextDecoder"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextDecoder) };
-void JSMD5_SHA1::finishCreation(VM& vm)
+void JSTextDecoder::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
-JSMD5_SHA1* JSMD5_SHA1::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) {
- JSMD5_SHA1* ptr = new (NotNull, JSC::allocateCell<JSMD5_SHA1>(vm)) JSMD5_SHA1(vm, structure, ctx);
+JSTextDecoder* JSTextDecoder::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) {
+ JSTextDecoder* ptr = new (NotNull, JSC::allocateCell<JSTextDecoder>(vm)) JSTextDecoder(vm, structure, ctx);
ptr->finishCreation(vm);
return ptr;
}
-extern "C" void* MD5_SHA1__fromJS(JSC::EncodedJSValue value) {
- JSMD5_SHA1* object = JSC::jsDynamicCast<JSMD5_SHA1*>(JSValue::decode(value));
+extern "C" void* TextDecoder__fromJS(JSC::EncodedJSValue value) {
+ JSTextDecoder* object = JSC::jsDynamicCast<JSTextDecoder*>(JSValue::decode(value));
if (!object)
return nullptr;
return object->wrapped();
}
-extern "C" bool MD5_SHA1__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) {
- JSMD5_SHA1* object = JSC::jsDynamicCast<JSMD5_SHA1*>(JSValue::decode(value));
+extern "C" bool TextDecoder__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) {
+ JSTextDecoder* object = JSC::jsDynamicCast<JSTextDecoder*>(JSValue::decode(value));
if (!object)
return false;
@@ -2096,11 +2090,11 @@ extern "C" bool MD5_SHA1__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr
}
-extern "C" const size_t MD5_SHA1__ptrOffset = JSMD5_SHA1::offsetOfWrapped();
+extern "C" const size_t TextDecoder__ptrOffset = JSTextDecoder::offsetOfWrapped();
-void JSMD5_SHA1::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+void JSTextDecoder::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
- auto* thisObject = jsCast<JSMD5_SHA1*>(cell);
+ auto* thisObject = jsCast<JSTextDecoder*>(cell);
if (void* wrapped = thisObject->wrapped()) {
// if (thisObject->scriptExecutionContext())
// analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
@@ -2108,10 +2102,21 @@ void JSMD5_SHA1::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
Base::analyzeHeap(cell, analyzer);
}
-JSObject* JSMD5_SHA1::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+JSObject* JSTextDecoder::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
{
- return JSMD5_SHA1Prototype::create(vm, globalObject, JSMD5_SHA1Prototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
-}extern "C" void* RequestClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+ return JSTextDecoderPrototype::create(vm, globalObject, JSTextDecoderPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+template<typename Visitor>
+void JSTextDecoder::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSTextDecoder* thisObject = jsCast<JSTextDecoder*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_encoding);
+}
+
+DEFINE_VISIT_CHILDREN(JSTextDecoder);extern "C" void* RequestClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
JSC_DECLARE_CUSTOM_GETTER(jsRequestConstructor);
extern "C" void RequestClass__finalize(void*);
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h
index 6b23611de..bc0a2ec6f 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses.h
@@ -1007,22 +1007,22 @@ class JSSHA512_256Prototype final : public JSC::JSNonFinalObject {
void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSSHA512_256Prototype* prototype);
};
-class JSMD5_SHA1 final : public JSC::JSDestructibleObject {
+class JSTextDecoder final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
- static JSMD5_SHA1* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+ static JSTextDecoder* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
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<JSMD5_SHA1, WebCore::UseCustomHeapCellType::No>(
+ return WebCore::subspaceForImpl<JSTextDecoder, WebCore::UseCustomHeapCellType::No>(
vm,
- [](auto& spaces) { return spaces.m_clientSubspaceForMD5_SHA1.get(); },
- [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForMD5_SHA1 = WTFMove(space); },
- [](auto& spaces) { return spaces.m_subspaceForMD5_SHA1.get(); },
- [](auto& spaces, auto&& space) { spaces.m_subspaceForMD5_SHA1 = WTFMove(space); });
+ [](auto& spaces) { return spaces.m_clientSubspaceForTextDecoder.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTextDecoder = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForTextDecoder.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForTextDecoder = WTFMove(space); });
}
static void destroy(JSC::JSCell*);
@@ -1033,7 +1033,7 @@ class JSMD5_SHA1 final : public JSC::JSDestructibleObject {
static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
- ~JSMD5_SHA1();
+ ~JSTextDecoder();
void* wrapped() const { return m_ctx; }
@@ -1043,12 +1043,12 @@ class JSMD5_SHA1 final : public JSC::JSDestructibleObject {
}
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
- static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSMD5_SHA1, m_ctx); }
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSTextDecoder, m_ctx); }
void* m_ctx { nullptr };
- JSMD5_SHA1(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ JSTextDecoder(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
m_ctx = sinkPtr;
@@ -1056,17 +1056,17 @@ class JSMD5_SHA1 final : public JSC::JSDestructibleObject {
void finishCreation(JSC::VM&);
-
+ DECLARE_VISIT_CHILDREN;
-
+ mutable JSC::WriteBarrier<JSC::Unknown> m_encoding;
};
-class JSMD5_SHA1Prototype final : public JSC::JSNonFinalObject {
+class JSTextDecoderPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
- static JSMD5_SHA1Prototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ static JSTextDecoderPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
{
- JSMD5_SHA1Prototype* ptr = new (NotNull, JSC::allocateCell<JSMD5_SHA1Prototype>(vm)) JSMD5_SHA1Prototype(vm, globalObject, structure);
+ JSTextDecoderPrototype* ptr = new (NotNull, JSC::allocateCell<JSTextDecoderPrototype>(vm)) JSTextDecoderPrototype(vm, globalObject, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
@@ -1083,7 +1083,7 @@ class JSMD5_SHA1Prototype final : public JSC::JSNonFinalObject {
}
private:
- JSMD5_SHA1Prototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ JSTextDecoderPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
: Base(vm, structure)
{
}
@@ -1091,10 +1091,10 @@ class JSMD5_SHA1Prototype final : public JSC::JSNonFinalObject {
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
- class JSMD5_SHA1Constructor final : public JSC::InternalFunction {
+ class JSTextDecoderConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
- static JSMD5_SHA1Constructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSMD5_SHA1Prototype* prototype);
+ static JSTextDecoderConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSTextDecoderPrototype* prototype);
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = false;
@@ -1108,28 +1108,28 @@ class JSMD5_SHA1Prototype final : public JSC::JSNonFinalObject {
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
- return WebCore::subspaceForImpl<JSMD5_SHA1Constructor, WebCore::UseCustomHeapCellType::No>(
+ return WebCore::subspaceForImpl<JSTextDecoderConstructor, WebCore::UseCustomHeapCellType::No>(
vm,
- [](auto& spaces) { return spaces.m_clientSubspaceForMD5_SHA1Constructor.get(); },
- [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForMD5_SHA1Constructor = WTFMove(space); },
- [](auto& spaces) { return spaces.m_subspaceForMD5_SHA1Constructor.get(); },
- [](auto& spaces, auto&& space) { spaces.m_subspaceForMD5_SHA1Constructor = WTFMove(space); });
+ [](auto& spaces) { return spaces.m_clientSubspaceForTextDecoderConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTextDecoderConstructor = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForTextDecoderConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForTextDecoderConstructor = WTFMove(space); });
}
- void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSMD5_SHA1Prototype* prototype);
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTextDecoderPrototype* prototype);
// Must be defined for each specialization class.
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
DECLARE_EXPORT_INFO;
private:
- JSMD5_SHA1Constructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ JSTextDecoderConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
: Base(vm, structure, nativeFunction, nativeFunction)
{
}
- void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSMD5_SHA1Prototype* prototype);
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSTextDecoderPrototype* prototype);
};
class JSRequest final : public JSC::JSDestructibleObject {
public:
diff --git a/src/bun.js/bindings/ZigGeneratedCode.cpp b/src/bun.js/bindings/ZigGeneratedCode.cpp
index 327ee7893..c563597b8 100644
--- a/src/bun.js/bindings/ZigGeneratedCode.cpp
+++ b/src/bun.js/bindings/ZigGeneratedCode.cpp
@@ -1,57 +1,61 @@
-#include "root.h"
-
-#include <JavaScriptCore/DOMJITAbstractHeap.h>
-#include "DOMJITIDLConvert.h"
-#include "DOMJITIDLType.h"
-#include "DOMJITIDLTypeFilter.h"
-#include "DOMJITHelpers.h"
-#include <JavaScriptCore/DFGAbstractHeap.h>
-
-#include "JSDOMConvertBufferSource.h"
-
-using namespace JSC;
-using namespace WebCore;
-
-/* -- BEGIN DOMCall DEFINITIONS -- */
+ #include "root.h"
+
+ #include <JavaScriptCore/DOMJITAbstractHeap.h>
+ #include "DOMJITIDLConvert.h"
+ #include "DOMJITIDLType.h"
+ #include "DOMJITIDLTypeFilter.h"
+ #include "DOMJITHelpers.h"
+ #include <JavaScriptCore/DFGAbstractHeap.h>
+
+ #include "JSDOMConvertBufferSource.h"
+
+ using namespace JSC;
+ using namespace WebCore;
+
+
+ /* -- BEGIN DOMCall DEFINITIONS -- */
+
extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper);
-extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
-
-JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1))
-{
- VM& vm = JSC::getVM(lexicalGlobalObject);
- IGNORE_WARNINGS_BEGIN("frame-address")
- CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
- IGNORE_WARNINGS_END
- JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
- return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
+extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
+
+JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) {
+VM& vm = JSC::getVM(lexicalGlobalObject);
+IGNORE_WARNINGS_BEGIN("frame-address")
+CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
+IGNORE_WARNINGS_END
+JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
+return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
}
-JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame))
-{
+JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) {
return FFI__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount());
}
-extern "C" void FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
-{
- JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value));
- static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
- FFI__ptr__fastpathWrapper,
- thisObject->classInfo(),
- JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()),
- JSC::SpecNonIntAsDouble,
- JSC::SpecUint8Array);
- JSFunction* function = JSFunction::create(
- globalObject->vm(),
- globalObject,
- 1,
- String("ptr"_s),
- FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
- &DOMJIT_ptr_signature);
- thisObject->putDirect(
- globalObject->vm(),
- Identifier::fromString(globalObject->vm(), "ptr"_s),
- function,
- JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0);
+extern "C" void FFI__ptr__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) {
+ JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value));
+ static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
+ FFI__ptr__fastpathWrapper,
+ thisObject->classInfo(),
+ JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()),
+ JSC::SpecNonIntAsDouble,
+ JSC::SpecUint8Array
+ );
+ JSFunction* function = JSFunction::create(
+ globalObject->vm(),
+ globalObject,
+ 1,
+ String("ptr"_s),
+ FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
+ &DOMJIT_ptr_signature
+ );
+ thisObject->putDirect(
+ globalObject->vm(),
+ Identifier::fromString(globalObject->vm(), "ptr"_s),
+ function,
+ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0
+ );
}
-/* -- END DOMCall DEFINITIONS-- */
+
+ /* -- END DOMCall DEFINITIONS-- */
+
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 762814d65..54fa5bad7 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -521,6 +521,17 @@ JSC_DEFINE_CUSTOM_GETTER(JSCloseEvent_getter,
WebCore::JSCloseEvent::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject));
}
+JSC_DECLARE_CUSTOM_GETTER(JSTextDecoder_getter);
+
+JSC_DEFINE_CUSTOM_GETTER(JSTextDecoder_getter,
+ (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue,
+ JSC::PropertyName))
+{
+ Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject);
+ return JSC::JSValue::encode(
+ thisObject->JSTextDecoderConstructor());
+}
+
JSC_DECLARE_CUSTOM_GETTER(JSMessageEvent_getter);
JSC_DEFINE_CUSTOM_GETTER(JSMessageEvent_getter,
@@ -2134,6 +2145,9 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Response"_s), JSC::CustomGetterSetter::create(vm, JSResponse_getter, nullptr),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+ putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "TextDecoder"_s), JSC::CustomGetterSetter::create(vm, JSTextDecoder_getter, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+
putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "DOMException"_s), JSC::CustomGetterSetter::create(vm, JSDOMException_getter, nullptr),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 05d220da9..36c22ae2f 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -1769,6 +1769,22 @@ pub const JSGlobalObject = extern struct {
this.vm().throwError(this, err);
}
+ pub fn throw(
+ this: *JSGlobalObject,
+ comptime fmt: string,
+ args: anytype,
+ ) void {
+ if (comptime std.meta.fieldNames(@TypeOf(args)).len > 0) {
+ var str = ZigString.init(std.fmt.allocPrint(this.bunVM().allocator, fmt, args) catch return);
+ str.markUTF8();
+ var err = str.toErrorInstance(this);
+ this.vm().throwError(this, err);
+ this.bunVM().allocator.free(ZigString.untagged(str.ptr)[0..str.len]);
+ } else {
+ this.vm().throwError(this, ZigString.init(fmt).toValue(this));
+ }
+ }
+
// pub fn createError(globalObject: *JSGlobalObject, error_type: ErrorType, message: *String) *JSObject {
// return cppFn("createError", .{ globalObject, error_type, message });
// }
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
index 92f3812f0..0bc48964c 100644
--- a/src/bun.js/bindings/generated_classes.zig
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -623,80 +623,74 @@ pub const JSSHA512_256 = struct {
}
}
};
-pub const JSMD5_SHA1 = struct {
- const MD5_SHA1 = Classes.MD5_SHA1;
- const GetterType = fn (*MD5_SHA1, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
- const SetterType = fn (*MD5_SHA1, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
- const CallbackType = fn (*MD5_SHA1, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+pub const JSTextDecoder = struct {
+ const TextDecoder = Classes.TextDecoder;
+ const GetterType = fn (*TextDecoder, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn (*TextDecoder, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn (*TextDecoder, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
/// Return the pointer to the wrapped object.
/// If the object does not match the type, return null.
- pub fn fromJS(value: JSC.JSValue) ?*MD5_SHA1 {
+ pub fn fromJS(value: JSC.JSValue) ?*TextDecoder {
JSC.markBinding();
- return MD5_SHA1__fromJS(value);
+ return TextDecoder__fromJS(value);
}
- /// Get the MD5_SHA1 constructor value.
+ /// Get the TextDecoder constructor value.
/// This loads lazily from the global object.
pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue {
JSC.markBinding();
- return MD5_SHA1__getConstructor(globalObject);
+ return TextDecoder__getConstructor(globalObject);
}
- /// Create a new instance of MD5_SHA1
- pub fn toJS(this: *MD5_SHA1, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ /// Create a new instance of TextDecoder
+ pub fn toJS(this: *TextDecoder, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
JSC.markBinding();
if (comptime Environment.allow_assert) {
- const value__ = MD5_SHA1__create(globalObject, this);
- std.debug.assert(value__.as(MD5_SHA1).? == this); // If this fails, likely a C ABI issue.
+ const value__ = TextDecoder__create(globalObject, this);
+ std.debug.assert(value__.as(TextDecoder).? == this); // If this fails, likely a C ABI issue.
return value__;
} else {
- return MD5_SHA1__create(globalObject, this);
+ return TextDecoder__create(globalObject, this);
}
}
- /// Modify the internal ptr to point to a new instance of MD5_SHA1.
- pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*MD5_SHA1) bool {
+ /// Modify the internal ptr to point to a new instance of TextDecoder.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*TextDecoder) bool {
JSC.markBinding();
- return MD5_SHA1__dangerouslySetPtr(value, ptr);
+ return TextDecoder__dangerouslySetPtr(value, ptr);
}
- extern fn MD5_SHA1__fromJS(JSC.JSValue) ?*MD5_SHA1;
- extern fn MD5_SHA1__getConstructor(*JSC.JSGlobalObject) JSC.JSValue;
+ extern fn TextDecoder__fromJS(JSC.JSValue) ?*TextDecoder;
+ extern fn TextDecoder__getConstructor(*JSC.JSGlobalObject) JSC.JSValue;
- extern fn MD5_SHA1__create(globalObject: *JSC.JSGlobalObject, ptr: ?*MD5_SHA1) JSC.JSValue;
+ extern fn TextDecoder__create(globalObject: *JSC.JSGlobalObject, ptr: ?*TextDecoder) JSC.JSValue;
- extern fn MD5_SHA1__dangerouslySetPtr(JSC.JSValue, ?*MD5_SHA1) bool;
+ extern fn TextDecoder__dangerouslySetPtr(JSC.JSValue, ?*TextDecoder) bool;
comptime {
- if (@TypeOf(MD5_SHA1.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*MD5_SHA1)) {
- @compileLog("MD5_SHA1.constructor is not a constructor");
+ if (@TypeOf(TextDecoder.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*TextDecoder)) {
+ @compileLog("TextDecoder.constructor is not a constructor");
}
- if (@TypeOf(MD5_SHA1.finalize) != (fn (*MD5_SHA1) callconv(.C) void)) {
- @compileLog("MD5_SHA1.finalize is not a finalizer");
+ if (@TypeOf(TextDecoder.finalize) != (fn (*TextDecoder) callconv(.C) void)) {
+ @compileLog("TextDecoder.finalize is not a finalizer");
}
- if (@TypeOf(MD5_SHA1.getByteLength) != GetterType)
- @compileLog("Expected MD5_SHA1.getByteLength to be a getter");
+ if (@TypeOf(TextDecoder.decode) != CallbackType)
+ @compileLog("Expected TextDecoder.decode to be a callback");
+ if (@TypeOf(TextDecoder.getEncoding) != GetterType)
+ @compileLog("Expected TextDecoder.getEncoding to be a getter");
- if (@TypeOf(MD5_SHA1.digest) != CallbackType)
- @compileLog("Expected MD5_SHA1.digest to be a callback");
- if (@TypeOf(MD5_SHA1.update) != CallbackType)
- @compileLog("Expected MD5_SHA1.update to be a callback");
- if (@TypeOf(MD5_SHA1.getByteLengthStatic) != StaticGetterType)
- @compileLog("Expected MD5_SHA1.getByteLengthStatic to be a static getter");
+ if (@TypeOf(TextDecoder.getFatal) != GetterType)
+ @compileLog("Expected TextDecoder.getFatal to be a getter");
- if (@TypeOf(MD5_SHA1.hash) != StaticCallbackType)
- @compileLog("Expected MD5_SHA1.hash to be a static callback");
if (!JSC.is_bindgen) {
- @export(MD5_SHA1.constructor, .{ .name = "MD5_SHA1Class__construct" });
- @export(MD5_SHA1.digest, .{ .name = "MD5_SHA1Prototype__digest" });
- @export(MD5_SHA1.finalize, .{ .name = "MD5_SHA1Class__finalize" });
- @export(MD5_SHA1.getByteLength, .{ .name = "MD5_SHA1Prototype__getByteLength" });
- @export(MD5_SHA1.getByteLengthStatic, .{ .name = "MD5_SHA1Class__getByteLengthStatic" });
- @export(MD5_SHA1.hash, .{ .name = "MD5_SHA1Class__hash" });
- @export(MD5_SHA1.update, .{ .name = "MD5_SHA1Prototype__update" });
+ @export(TextDecoder.constructor, .{ .name = "TextDecoderClass__construct" });
+ @export(TextDecoder.decode, .{ .name = "TextDecoderPrototype__decode" });
+ @export(TextDecoder.finalize, .{ .name = "TextDecoderClass__finalize" });
+ @export(TextDecoder.getEncoding, .{ .name = "TextDecoderPrototype__getEncoding" });
+ @export(TextDecoder.getFatal, .{ .name = "TextDecoderPrototype__getFatal" });
}
}
};
@@ -935,3 +929,17 @@ pub const JSResponse = struct {
}
}
};
+
+comptime {
+ _ = JSSHA1;
+ _ = JSMD5;
+ _ = JSMD4;
+ _ = JSSHA224;
+ _ = JSSHA512;
+ _ = JSSHA384;
+ _ = JSSHA256;
+ _ = JSSHA512_256;
+ _ = JSTextDecoder;
+ _ = JSRequest;
+ _ = JSResponse;
+}
diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig
index 5494e37e7..f491b52a0 100644
--- a/src/bun.js/bindings/generated_classes_list.zig
+++ b/src/bun.js/bindings/generated_classes_list.zig
@@ -11,5 +11,5 @@ pub const Classes = struct {
pub const SHA384 = JSC.API.Bun.Crypto.SHA384;
pub const SHA256 = JSC.API.Bun.Crypto.SHA256;
pub const SHA512_256 = JSC.API.Bun.Crypto.SHA512_256;
- pub const MD5_SHA1 = JSC.API.Bun.Crypto.MD5_SHA1;
+ pub const TextDecoder = JSC.WebCore.TextDecoder;
};
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index b466e1df2..e7f4880bd 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1660746106
+//-- AUTOGENERATED FILE -- 1660803660
#pragma once
#include <stddef.h>
diff --git a/src/bun.js/bindings/shimmer.zig b/src/bun.js/bindings/shimmer.zig
index c180fc864..2783439b3 100644
--- a/src/bun.js/bindings/shimmer.zig
+++ b/src/bun.js/bindings/shimmer.zig
@@ -5,7 +5,8 @@ pub const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false
const headers = @import("./headers.zig");
fn isNullableType(comptime Type: type) bool {
- return @typeInfo(Type) == .Optional;
+ return @typeInfo(Type) == .Optional or
+ (@typeInfo(Type) == .Pointer and @typeInfo(Type).Pointer.is_allowzero);
}
pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comptime Parent: type) type {
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index b52ba562f..bfb6fd024 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -88,7 +88,6 @@ const EventLoop = JSC.EventLoop;
const ThreadSafeFunction = JSC.napi.ThreadSafeFunction;
pub const GlobalConstructors = [_]type{
WebCore.Blob.Constructor,
- WebCore.TextDecoder.Constructor,
JSC.Cloudflare.HTMLRewriter.Constructor,
};
@@ -366,7 +365,7 @@ pub const VirtualMachine = struct {
pub inline fn nodeFS(this: *VirtualMachine) *Node.NodeFS {
return this.node_fs orelse brk: {
this.node_fs = bun.default_allocator.create(Node.NodeFS) catch unreachable;
- this.node_fs.?.* = Node.NodeFS{ .async_io = undefined };
+ this.node_fs.?.* = Node.NodeFS{};
break :brk this.node_fs.?;
};
}
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig
index 607dd00f4..fad9da954 100644
--- a/src/bun.js/node/node_fs.zig
+++ b/src/bun.js/node/node_fs.zig
@@ -2314,8 +2314,6 @@ const Return = struct {
/// https://nodejs.org/api/fs.html
/// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/fs.d.ts
pub const NodeFS = struct {
- async_io: *AsyncIO,
-
/// Buffer to store a temporary file path that might appear in a returned error message.
///
/// We want to avoid allocating a new path buffer for every error message so that JSC can clone + GC it.
diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts
index 3f8d4876b..eb93e6cd2 100644
--- a/src/bun.js/scripts/generate-classes.ts
+++ b/src/bun.js/scripts/generate-classes.ts
@@ -1,3 +1,4 @@
+import { unlinkSync } from "fs";
import { readdirSync } from "fs";
import { resolve } from "path";
import type { Field, ClassDefinition } from "./class-definitions";
@@ -1232,26 +1233,41 @@ function findClasses() {
const classes = findClasses();
-await Bun.write(`${import.meta.dir}/../bindings/generated_classes.zig`, [
+function writeAndUnlink(path, content) {
+ try {
+ unlinkSync(path);
+ } catch (e) {}
+ return Bun.write(path, content);
+}
+
+await writeAndUnlink(`${import.meta.dir}/../bindings/generated_classes.zig`, [
ZIG_GENERATED_CLASSES_HEADER,
+
...classes.map((a) => generateZig(a.name, a).trim()).join("\n"),
+ "\n",
+ `
+comptime {
+ ${classes.map((a) => `_ = ${className(a.name)};`).join("\n ")}
+}
+
+ `,
]);
-await Bun.write(`${import.meta.dir}/../bindings/ZigGeneratedClasses.h`, [
+await writeAndUnlink(`${import.meta.dir}/../bindings/ZigGeneratedClasses.h`, [
GENERATED_CLASSES_HEADER,
...classes.map((a) => generateHeader(a.name, a)),
GENERATED_CLASSES_FOOTER,
]);
-await Bun.write(`${import.meta.dir}/../bindings/ZigGeneratedClasses.cpp`, [
+await writeAndUnlink(`${import.meta.dir}/../bindings/ZigGeneratedClasses.cpp`, [
GENERATED_CLASSES_IMPL_HEADER,
...classes.map((a) => generateImpl(a.name, a)),
GENERATED_CLASSES_IMPL_FOOTER,
]);
-await Bun.write(
+await writeAndUnlink(
`${import.meta.dir}/../bindings/ZigGeneratedClasses+lazyStructureHeader.h`,
classes.map((a) => generateLazyClassStructureHeader(a.name, a)).join("\n")
);
-await Bun.write(
+await writeAndUnlink(
`${import.meta.dir}/../bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h`,
classes.map((a) =>
[
@@ -1263,7 +1279,7 @@ await Bun.write(
)
);
-await Bun.write(
+await writeAndUnlink(
`${import.meta.dir}/../bindings/ZigGeneratedClasses+DOMIsoSubspaces.h`,
classes.map((a) =>
[
@@ -1273,7 +1289,7 @@ await Bun.write(
)
);
-await Bun.write(
+await writeAndUnlink(
`${import.meta.dir}/../bindings/ZigGeneratedClasses+lazyStructureImpl.h`,
initLazyClasses(
classes.map((a) => generateLazyClassStructureImpl(a.name, a))
diff --git a/src/bun.js/typescript.zig b/src/bun.js/typescript.zig
index 6095320f6..725226781 100644
--- a/src/bun.js/typescript.zig
+++ b/src/bun.js/typescript.zig
@@ -40,7 +40,6 @@ pub fn main() anyerror!void {
JSC.WebCore.Fetch.Class.typescriptDeclaration(),
JSC.Performance.Class.typescriptDeclaration(),
JSC.Crypto.Class.typescriptDeclaration(),
- JSC.WebCore.TextDecoder.Class.typescriptDeclaration(),
JSC.API.Transpiler.Class.typescriptDeclaration(),
};
diff --git a/src/bun.js/webcore/encoding.classes.ts b/src/bun.js/webcore/encoding.classes.ts
new file mode 100644
index 000000000..777f3715e
--- /dev/null
+++ b/src/bun.js/webcore/encoding.classes.ts
@@ -0,0 +1,25 @@
+import { define } from "../scripts/class-definitions";
+
+export default [
+ define({
+ name: "TextDecoder",
+ construct: true,
+ finalize: true,
+ JSType: "0b11101110",
+ klass: {},
+ proto: {
+ encoding: {
+ getter: "getEncoding",
+ cache: true,
+ },
+ fatal: {
+ getter: "getFatal",
+ },
+
+ decode: {
+ fn: "decode",
+ length: 1,
+ },
+ },
+ }),
+];
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig
index 6e06a06f4..afde916c1 100644
--- a/src/bun.js/webcore/encoding.zig
+++ b/src/bun.js/webcore/encoding.zig
@@ -404,82 +404,50 @@ pub const TextDecoder = struct {
fatal: bool = false,
encoding: EncodingLabel = EncodingLabel.utf8,
- pub const Class = NewClass(
- TextDecoder,
- .{
- .name = "TextDecoder",
- },
- .{
- .decode = .{
- .rfn = decode,
- },
- },
- .{
- .encoding = .{
- .get = getEncoding,
- .readOnly = true,
- },
- .ignoreBOM = .{
- .get = getIgnoreBOM,
- .set = setIgnoreBOM,
- },
- .fatal = .{
- .get = getFatal,
- .set = setFatal,
- },
- },
- );
+ pub fn finalize(this: *TextDecoder) callconv(.C) void {
+ bun.default_allocator.destroy(this);
+ }
+
+ pub usingnamespace JSC.Codegen.JSTextDecoder;
pub fn getIgnoreBOM(
this: *TextDecoder,
- _: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return JSC.JSValue.jsBoolean(this.ignore_bom).asObjectRef();
- }
- pub fn setIgnoreBOM(
- this: *TextDecoder,
- _: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- value: JSC.C.JSValueRef,
- _: js.ExceptionRef,
- ) bool {
- this.ignore_bom = JSValue.fromRef(value).toBoolean();
- return true;
- }
- pub fn setFatal(
- this: *TextDecoder,
- _: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- value: JSC.C.JSValueRef,
- _: js.ExceptionRef,
- ) bool {
- this.fatal = JSValue.fromRef(value).toBoolean();
- return true;
- }
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return JSC.JSValue.jsBoolean(this.ignore_bom);
+ }
+ // pub fn setIgnoreBOM(
+ // this: *TextDecoder,
+ // _: *JSC.JSGlobalObject,
+ // ) callconv(.C) JSC.JSValue {
+ // this.ignore_bom = JSValue.fromRef(this.ignore_bom).toBoolean();
+ // return true;
+ // }
+
+ // pub fn setFatal(
+ // this: *TextDecoder,
+ // _: js.JSContextRef,
+ // _: js.JSValueRef,
+ // _: js.JSStringRef,
+ // value: JSC.C.JSValueRef,
+ // _: js.ExceptionRef,
+ // ) bool {
+ // this.fatal = JSValue.fromRef(value).toBoolean();
+ // return true;
+ // }
pub fn getFatal(
this: *TextDecoder,
- _: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return JSC.JSValue.jsBoolean(this.fatal).asObjectRef();
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return JSC.JSValue.jsBoolean(this.fatal);
}
const utf8_string: string = "utf-8";
pub fn getEncoding(
this: *TextDecoder,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return ZigString.init(EncodingLabel.label.get(this.encoding).?).toValue(ctx.ptr()).asObjectRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init(EncodingLabel.label.get(this.encoding).?).toValue(globalThis);
}
const Vector16 = std.meta.Vector(16, u16);
const max_16_ascii: Vector16 = @splat(16, @as(u16, 127));
@@ -489,7 +457,7 @@ pub const TextDecoder = struct {
comptime Slice: type,
slice: Slice,
ctx: js.JSContextRef,
- ) JSC.C.JSValueRef {
+ ) JSC.JSValue {
var i: usize = 0;
while (i < slice.len) {
@@ -519,13 +487,13 @@ pub const TextDecoder = struct {
// we can still allocate as UTF-16 and just copy the bytes
if (i == slice.len) {
if (comptime Slice == []u16) {
- return JSC.C.JSValueMakeString(ctx, JSC.C.JSStringCreateWithCharacters(slice.ptr, slice.len));
+ return ZigString.init16(slice).toValueGC(ctx);
} else {
var str = ZigString.init("");
str.ptr = @ptrCast([*]u8, slice.ptr);
str.len = slice.len;
str.markUTF16();
- return str.toValueGC(ctx.ptr()).asObjectRef();
+ return str.toValueGC(ctx.ptr());
}
}
@@ -598,38 +566,29 @@ pub const TextDecoder = struct {
out.ptr = @ptrCast([*]u8, full.ptr);
out.len = full.len;
out.markUTF16();
- return out.toValueGC(ctx.ptr()).asObjectRef();
+ return out.toValueGC(ctx.ptr());
}
- pub fn decode(
- this: *TextDecoder,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- args: []const js.JSValueRef,
- exception: js.ExceptionRef,
- ) js.JSValueRef {
- const arguments: []const JSC.JSValue = @ptrCast([*]const JSC.JSValue, args.ptr)[0..args.len];
+ pub fn decode(this: *TextDecoder, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
+ const arguments_ = callframe.arguments(2);
+ const arguments = arguments_.ptr[0..arguments_.len];
if (arguments.len < 1 or arguments[0].isUndefined()) {
- return ZigString.Empty.toValue(ctx.ptr()).asObjectRef();
+ return ZigString.Empty.toValue(globalThis);
}
- const array_buffer = arguments[0].asArrayBuffer(ctx.ptr()) orelse {
- JSC.throwInvalidArguments("TextDecoder.decode expects an ArrayBuffer or TypedArray", .{}, ctx, exception);
- return null;
+ const array_buffer = arguments[0].asArrayBuffer(globalThis) orelse {
+ globalThis.throwInvalidArguments("TextDecoder.decode expects an ArrayBuffer or TypedArray", .{});
+ return JSValue.zero;
};
if (array_buffer.len == 0) {
- return ZigString.Empty.toValue(ctx.ptr()).asObjectRef();
+ return ZigString.Empty.toValue(globalThis);
}
- JSC.C.JSValueProtect(ctx, args[0]);
- defer JSC.C.JSValueUnprotect(ctx, args[0]);
-
switch (this.encoding) {
EncodingLabel.@"latin1" => {
- return ZigString.init(array_buffer.slice()).toValueGC(ctx.ptr()).asObjectRef();
+ return ZigString.init(array_buffer.slice()).toValueGC(globalThis);
},
EncodingLabel.@"UTF-8" => {
const buffer_slice = array_buffer.slice();
@@ -637,89 +596,85 @@ pub const TextDecoder = struct {
if (this.fatal) {
if (strings.toUTF16Alloc(default_allocator, buffer_slice, true)) |result_| {
if (result_) |result| {
- return ZigString.toExternalU16(result.ptr, result.len, ctx.ptr()).asObjectRef();
+ return ZigString.toExternalU16(result.ptr, result.len, globalThis);
}
} else |err| {
switch (err) {
error.InvalidByteSequence => {
- JSC.JSError(default_allocator, "Invalid byte sequence", .{}, ctx, exception);
- return null;
+ globalThis.throw("Invalid byte sequence", .{});
+ return JSValue.zero;
},
error.OutOfMemory => {
- JSC.JSError(default_allocator, "Out of memory", .{}, ctx, exception);
- return null;
+ globalThis.throw("Out of memory", .{});
+ return JSValue.zero;
},
else => {
- JSC.JSError(default_allocator, "Unknown error", .{}, ctx, exception);
- return null;
+ globalThis.throw("Unknown error", .{});
+ return JSValue.zero;
},
}
}
} else {
if (strings.toUTF16Alloc(default_allocator, buffer_slice, false)) |result_| {
if (result_) |result| {
- return ZigString.toExternalU16(result.ptr, result.len, ctx.ptr()).asObjectRef();
+ return ZigString.toExternalU16(result.ptr, result.len, globalThis);
}
} else |err| {
switch (err) {
error.OutOfMemory => {
- JSC.JSError(default_allocator, "Out of memory", .{}, ctx, exception);
- return null;
+ globalThis.throw("Out of memory", .{});
+ return JSValue.zero;
},
else => {
- JSC.JSError(default_allocator, "Unknown error", .{}, ctx, exception);
- return null;
+ globalThis.throw("Unknown error", .{});
+ return JSValue.zero;
},
}
}
}
// Experiment: using mimalloc directly is slightly slower
- return ZigString.init(buffer_slice).toValueGC(ctx.ptr()).asObjectRef();
+ return ZigString.init(buffer_slice).toValueGC(globalThis);
},
EncodingLabel.@"UTF-16LE" => {
if (std.mem.isAligned(@ptrToInt(array_buffer.ptr) + @as(usize, array_buffer.offset), @alignOf([*]u16))) {
- return this.decodeUTF16WithAlignment([]u16, array_buffer.asU16(), ctx);
+ return this.decodeUTF16WithAlignment([]u16, array_buffer.asU16(), globalThis);
}
- return this.decodeUTF16WithAlignment([]align(1) u16, array_buffer.asU16Unaligned(), ctx);
+ return this.decodeUTF16WithAlignment([]align(1) u16, array_buffer.asU16Unaligned(), globalThis);
},
else => {
- JSC.throwInvalidArguments("TextDecoder.decode set to unsupported encoding", .{}, ctx, exception);
- return null;
+ globalThis.throwInvalidArguments("TextDecoder.decode set to unsupported encoding", .{});
+ return JSValue.zero;
},
}
}
- pub const Constructor = JSC.NewConstructor(TextDecoder, .{
- .constructor = .{ .rfn = constructor },
- }, .{});
-
pub fn constructor(
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- args_: []const js.JSValueRef,
- exception: js.ExceptionRef,
- ) js.JSObjectRef {
- var arguments: []const JSC.JSValue = @ptrCast([*]const JSC.JSValue, args_.ptr)[0..args_.len];
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) ?*TextDecoder {
+ var args_ = callframe.arguments(1);
+ var arguments: []const JSC.JSValue = args_.ptr[0..args_.len];
+
var encoding = EncodingLabel.@"UTF-8";
if (arguments.len > 0) {
if (!arguments[0].isString()) {
- JSC.throwInvalidArguments("TextDecoder(encoding) label is invalid", .{}, ctx, exception);
+ globalThis.throwInvalidArguments("TextDecoder(encoding) label is invalid", .{});
return null;
}
- var str = arguments[0].toSlice(ctx.ptr(), default_allocator);
+ var str = arguments[0].toSlice(globalThis, default_allocator);
defer if (str.allocated) str.deinit();
encoding = EncodingLabel.which(str.slice()) orelse {
- JSC.throwInvalidArguments("Unsupported encoding label \"{s}\"", .{str.slice()}, ctx, exception);
+ globalThis.throwInvalidArguments("Unsupported encoding label \"{s}\"", .{str.slice()});
return null;
};
}
- var decoder = getAllocator(ctx).create(TextDecoder) catch unreachable;
+ var decoder = getAllocator(globalThis).create(TextDecoder) catch unreachable;
decoder.* = TextDecoder{ .encoding = encoding };
- return TextDecoder.Class.make(ctx, decoder);
+ return decoder;
}
};