diff options
author | 2022-04-28 18:24:12 -0700 | |
---|---|---|
committer | 2022-04-29 00:47:26 -0700 | |
commit | e26f96b748d783828669d46068f744f5852b6ba9 (patch) | |
tree | 61d2708b07d9e302c2221ae3ef798a60c60fe314 | |
parent | 8fa1c5ebf116571f41fb93065f728bd6437ae2d8 (diff) | |
download | bun-e26f96b748d783828669d46068f744f5852b6ba9.tar.gz bun-e26f96b748d783828669d46068f744f5852b6ba9.tar.zst bun-e26f96b748d783828669d46068f744f5852b6ba9.zip |
wip
-rw-r--r-- | bench/snippets/buffer.js | 129 | ||||
-rw-r--r-- | src/javascript/jsc/api/ffi.zig | 8 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/BunBuiltinNames.h | 1 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp | 68 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h | 52 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/WebCoreJSBuiltins.h | 52 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/ZigGlobalObject.cpp | 4 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/ZigGlobalObject.h | 5 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/bindings.zig | 8 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/root.h | 1 |
10 files changed, 312 insertions, 16 deletions
diff --git a/bench/snippets/buffer.js b/bench/snippets/buffer.js new file mode 100644 index 000000000..4647249dd --- /dev/null +++ b/bench/snippets/buffer.js @@ -0,0 +1,129 @@ +// import { Buffer } from "buffer"; +var buf = new Buffer(1024); +var view = new DataView(buf.buffer); +var INTERVAL = 9999999; +var time = (name, fn) => { + for (let i = 0; i < INTERVAL; i++) fn(); + + console.time(name.padEnd("DataView.readBigUInt64 (LE)".length)); + for (let i = 0; i < INTERVAL; i++) fn(); + console.timeEnd(name.padEnd("DataView.readBigUInt64 (LE)".length)); +}; + +console.log( + `Run ${new Intl.NumberFormat().format(INTERVAL)} times with a warmup:`, + "\n" +); + +time("Buffer.readBigInt64BE ", () => buf.readBigInt64BE(0)); +// time("DataView.getBigInt64 (BE)", () => view.getBigInt64(0, false)); +// console.log(""); +time("Buffer.readBigInt64LE ", () => buf.readBigInt64LE(0)); +// time("DataView.readBigInt64 (LE)", () => view.getBigInt64(0, true)); +// console.log(""); +time("Buffer.readBigUInt64BE ", () => buf.readBigUInt64BE(0)); +// time("DataView.getBigUInt64 (BE)", () => view.getBigUint64(0, false)); +// console.log(""); +time("Buffer.readBigUInt64LE ", () => buf.readBigUInt64LE(0)); +// time("DataView.readBigUInt64 (LE)", () => view.getBigUint64(0, true)); +// console.log(""); +time("Buffer.readDoubleBE ", () => buf.readDoubleBE(0)); +// time("DataView.getDouble (BE)", () => view.getFloat64(0, false)); +// console.log(""); +time("Buffer.readDoubleLE ", () => buf.readDoubleLE(0)); +// time("DataView.readDouble (LE)", () => view.getFloat64(0, true)); +// console.log(""); +time("Buffer.readFloatBE ", () => buf.readFloatBE(0)); +// time("DataView.getFloat (BE)", () => view.getFloat32(0, false)); +// console.log(""); +time("Buffer.readFloatLE ", () => buf.readFloatLE(0)); +// time("DataView.readFloat (LE)", () => view.getFloat32(0, true)); +// console.log(""); +time("Buffer.readInt16BE ", () => buf.readInt16BE(0)); +// time("DataView.getInt16 (BE)", () => view.getInt16(0, false)); +// console.log(""); +time("Buffer.readInt16LE ", () => buf.readInt16LE(0)); +// time("DataView.readInt16 (LE)", () => view.getInt16(0, true)); +// console.log(""); +time("Buffer.readInt32BE ", () => buf.readInt32BE(0)); +// time("DataView.getInt32 (BE)", () => view.getInt32(0, false)); +// console.log(""); +time("Buffer.readInt32LE ", () => buf.readInt32LE(0)); +// time("DataView.readInt32 (LE)", () => view.getInt32(0, true)); +// console.log(""); +time("Buffer.readInt8 ", () => buf.readInt8(0)); +// time("DataView.readInt (t8)", () => view.getInt8(0)); +// console.log(""); +time("Buffer.readUInt16BE ", () => buf.readUInt16BE(0)); +// time("DataView.getUInt16 (BE)", () => view.getUint16(0, false)); +// console.log(""); +time("Buffer.readUInt16LE ", () => buf.readUInt16LE(0)); +// time("DataView.readUInt16 (LE)", () => view.getUint16(0, true)); +// console.log(""); +time("Buffer.readUInt32BE ", () => buf.readUInt32BE(0)); +// time("DataView.getUInt32 (BE)", () => view.getUint32(0, false)); +// console.log(""); +time("Buffer.readUInt32LE ", () => buf.readUInt32LE(0)); +// time("DataView.getUInt32 (LE)", () => view.getUint32(0, true)); +// console.log(""); +time("Buffer.readUInt8 ", () => buf.readUInt8(0)); +// time("DataView.getUInt (t8)", () => view.getUint8(0)); +// console.log(""); + +time("Buffer.writeBigInt64BE", () => buf.writeBigInt64BE(BigInt(0), 0)); +// time("DataView.getBigInt64 (BE)", () => view.getBigInt64(0, false)); +// console.log(""); +time("Buffer.writeBigInt64LE", () => buf.writeBigInt64LE(BigInt(0), 0)); +// time("DataView.readBigInt64 (LE)", () => view.getBigInt64(0, true)); +// console.log(""); +time("Buffer.writeBigUInt64BE", () => buf.writeBigUInt64BE(BigInt(0), 0)); +// time("DataView.getBigUInt64 (BE)", () => view.getBigUint64(0, false)); +// console.log(""); +time("Buffer.writeBigUInt64LE", () => buf.writeBigUInt64LE(BigInt(0), 0)); +// time("DataView.readBigUInt64 (LE)", () => view.getBigUint64(0, true)); +// console.log(""); +time("Buffer.writeDoubleBE ", () => buf.writeDoubleBE(0, 0)); +// time("DataView.getDouble (BE)", () => view.getFloat64(0, false)); +// console.log(""); +time("Buffer.writeDoubleLE ", () => buf.writeDoubleLE(0, 0)); +// time("DataView.readDouble (LE)", () => view.getFloat64(0, true)); +// console.log(""); +time("Buffer.writeFloatBE ", () => buf.writeFloatBE(0, 0)); +// time("DataView.getFloat (BE)", () => view.getFloat32(0, false)); +// console.log(""); +time("Buffer.writeFloatLE ", () => buf.writeFloatLE(0, 0)); +// time("DataView.readFloat (LE)", () => view.getFloat32(0, true)); +// console.log(""); +time("Buffer.writeInt16BE ", () => buf.writeInt16BE(0, 0)); +// time("DataView.getInt16 (BE)", () => view.getInt16(0, false)); +// console.log(""); +time("Buffer.writeInt16LE ", () => buf.writeInt16LE(0, 0)); +// time("DataView.readInt16 (LE)", () => view.getInt16(0, true)); +// console.log(""); +time("Buffer.writeInt32BE ", () => buf.writeInt32BE(0, 0)); +// time("DataView.getInt32 (BE)", () => view.getInt32(0, false)); +// console.log(""); +time("Buffer.writeInt32LE ", () => buf.writeInt32LE(0, 0)); +// time("DataView.readInt32 (LE)", () => view.getInt32(0, true)); +// console.log(""); +time("Buffer.writeInt8 ", () => buf.writeInt8(0, 0)); +// time("DataView.readInt (t8)", () => view.getInt8(0)); +// console.log(""); +time("Buffer.writeUInt16BE ", () => buf.writeUInt16BE(0, 0)); +// time("DataView.getUInt16 (BE)", () => view.getUint16(0, false)); +// console.log(""); +time("Buffer.writeUInt16LE ", () => buf.writeUInt16LE(0, 0)); +// time("DataView.readUInt16 (LE)", () => view.getUint16(0, true)); +// console.log(""); +time("Buffer.writeUInt32BE ", () => buf.writeUInt32BE(0, 0)); +// time("DataView.getUInt32 (BE)", () => view.getUint32(0, false)); +// console.log(""); +time("Buffer.writeUInt32LE ", () => buf.writeUInt32LE(0, 0)); +// time("DataView.getUInt32 (LE)", () => view.getUint32(0, true)); +// console.log(""); +time("Buffer.writeUInt8 ", () => buf.writeUInt8(0, 0)); +// time("DataView.getUInt (t8)", () => view.getUint8(0)); +// console.log(""); + +buf.writeUInt8(10, 10); +console.assert(buf.readUInt8(10, 10) === 10); diff --git a/src/javascript/jsc/api/ffi.zig b/src/javascript/jsc/api/ffi.zig index a6191beb0..4062baadb 100644 --- a/src/javascript/jsc/api/ffi.zig +++ b/src/javascript/jsc/api/ffi.zig @@ -574,8 +574,6 @@ pub const FFI = struct { .{ "char*", ABIType{ .pointer = .{ .primitive = Primitive.Tag.char } } }, .{ "void*", ABIType{ .pointer = .{ .primitive = Primitive.Tag.@"void" } } }, - .{ "const char*", ABIType{ .pointer = .{ .is_const = true, .primitive = Primitive.Tag.char } } }, - .{ "const void*", ABIType{ .pointer = .{ .is_const = true, .primitive = Primitive.Tag.@"void" } } }, }, ); @@ -662,16 +660,12 @@ pub const FFI = struct { char: i8, int8_t: i8, uint8_t: u8, - int16_t: i16, uint16_t: u16, - int32_t: c_int, uint32_t: c_uint, - int64_t: i64, uint64_t: u64, - double: f64, float: f32, @@ -744,7 +738,7 @@ pub const FFI = struct { .bool => { try writer.print("BOOLEAN_TO_JSVALUE({s})", .{self.symbol}); }, - .int8_t, .uint8_t, .int16_t, .uint16_t, .int32_t, .uint32_t => { + .char, .int8_t, .uint8_t, .int16_t, .uint16_t, .int32_t, .uint32_t => { try writer.print("INT32_TO_JSVALUE({s})", .{self.symbol}); }, .int64_t => {}, diff --git a/src/javascript/jsc/bindings/BunBuiltinNames.h b/src/javascript/jsc/bindings/BunBuiltinNames.h index 26d151319..f02a92e17 100644 --- a/src/javascript/jsc/bindings/BunBuiltinNames.h +++ b/src/javascript/jsc/bindings/BunBuiltinNames.h @@ -95,6 +95,7 @@ using namespace JSC; macro(version) \ macro(versions) \ macro(write) \ + macro(dataView) \ BUN_ADDITIONAL_PRIVATE_IDENTIFIERS(macro) \ class BunBuiltinNames { diff --git a/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp b/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp new file mode 100644 index 000000000..bf85a29ef --- /dev/null +++ b/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#include "config.h" +#include "WebCoreJSBuiltinInternals.h" + +#include "JSDOMGlobalObject.h" +#include "WebCoreJSClientData.h" +#include <JavaScriptCore/HeapInlines.h> +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <JavaScriptCore/SlotVisitorInlines.h> +#include <JavaScriptCore/StructureInlines.h> + +namespace WebCore { + +JSBuiltinInternalFunctions::JSBuiltinInternalFunctions(JSC::VM& vm) + : m_vm(vm) +{ + UNUSED_PARAM(vm); +} + +template<typename Visitor> +void JSBuiltinInternalFunctions::visit(Visitor& visitor) +{ + UNUSED_PARAM(visitor); +} + +template void JSBuiltinInternalFunctions::visit(AbstractSlotVisitor&); +template void JSBuiltinInternalFunctions::visit(SlotVisitor&); + +SUPPRESS_ASAN void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& globalObject) +{ + UNUSED_PARAM(globalObject); + + JSVMClientData& clientData = *static_cast<JSVMClientData*>(m_vm.clientData); + JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = { + }; + //globalObject.addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals)); + UNUSED_PARAM(clientData); +} + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h b/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h new file mode 100644 index 000000000..86fb9b3c6 --- /dev/null +++ b/src/javascript/jsc/bindings/WebCoreJSBuiltinInternals.h @@ -0,0 +1,52 @@ +namespace Zig { class GlobalObject; } +/* + * Copyright (c) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#pragma once + +#include <JavaScriptCore/VM.h> +#include <JavaScriptCore/WeakInlines.h> + +namespace WebCore { + +using JSDOMGlobalObject = Zig::GlobalObject; + +class JSBuiltinInternalFunctions { +public: + explicit JSBuiltinInternalFunctions(JSC::VM&); + + template<typename Visitor> void visit(Visitor&); + void initialize(JSDOMGlobalObject&); + + +private: + JSC::VM& m_vm; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/WebCoreJSBuiltins.h b/src/javascript/jsc/bindings/WebCoreJSBuiltins.h new file mode 100644 index 000000000..f2fd32881 --- /dev/null +++ b/src/javascript/jsc/bindings/WebCoreJSBuiltins.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py + +#pragma once + +#include "JSBufferPrototypeBuiltins.h" +#include <JavaScriptCore/VM.h> + +namespace WebCore { + +class JSBuiltinFunctions { +public: + explicit JSBuiltinFunctions(JSC::VM& vm) + : m_vm(vm) + , m_jsBufferPrototypeBuiltins(m_vm) + { + } + + JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } + +private: + JSC::VM& m_vm; + JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; +}; + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index 8e522ab85..d613d6c61 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -87,7 +87,7 @@ #include "Process.h" #include "JavaScriptCore/RemoteInspectorServer.h" - +#include "WebCoreJSBuiltinInternals.h" #include "JSBuffer.h" using JSGlobalObject = JSC::JSGlobalObject; @@ -290,8 +290,10 @@ GlobalObject::GlobalObject(JSC::VM& vm, JSC::Structure* structure) , m_constructors(makeUnique<WebCore::DOMConstructors>()) , m_world(WebCore::DOMWrapperWorld::create(vm, WebCore::DOMWrapperWorld::Type::Normal)) , m_worldIsNormal(true) + , m_builtinInternalFunctions(vm) { + m_scriptExecutionContext = new WebCore::ScriptExecutionContext(&vm, this); } diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.h b/src/javascript/jsc/bindings/ZigGlobalObject.h index da67f93c1..e3914d447 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.h +++ b/src/javascript/jsc/bindings/ZigGlobalObject.h @@ -22,6 +22,7 @@ class ScriptExecutionContext; #include "JavaScriptCore/JSGlobalObject.h" #include "JavaScriptCore/JSTypeInfo.h" #include "JavaScriptCore/Structure.h" +#include "WebCoreJSBuiltinInternals.h" #include "ZigConsoleClient.h" @@ -125,8 +126,12 @@ public: JSC::JSPromiseRejectionOperation); void setConsole(void* console); void installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm); + WebCore::JSBuiltinInternalFunctions& builtinInternalFunctions() { return m_builtinInternalFunctions; } private: + void addBuiltinGlobals(JSC::VM&); + friend void WebCore::JSBuiltinInternalFunctions::initialize(Zig::GlobalObject&); + WebCore::JSBuiltinInternalFunctions m_builtinInternalFunctions; GlobalObject(JSC::VM& vm, JSC::Structure* structure); std::unique_ptr<WebCore::DOMConstructors> m_constructors; uint8_t m_worldIsNormal; diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index 840f9025e..63848164a 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -3488,11 +3488,3 @@ pub const WTF = struct { pub const Callback = struct { // zig: Value, }; - -const NodeBuffer = @import("../node/buffer.zig"); - -comptime { - if (!JSC.is_bindgen) { - std.testing.refAllDecls(NodeBuffer.Write); - } -} diff --git a/src/javascript/jsc/bindings/root.h b/src/javascript/jsc/bindings/root.h index ec2d228f7..0e8f2b262 100644 --- a/src/javascript/jsc/bindings/root.h +++ b/src/javascript/jsc/bindings/root.h @@ -78,4 +78,5 @@ #define WTF_MAKE_ISO_ALLOCATED_EXPORT(className, a) WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(className); #define WTF_MAKE_ISO_ALLOCATED_IMPL(className) + #endif
\ No newline at end of file |