Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: remove secret hidden internals and introduce new way to call native code from js #8166

Merged
merged 38 commits into from Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1baf79c
oooooh magic
paperdave Jan 14, 2024
ca99e27
stuff
paperdave Jan 15, 2024
80b4735
run format
paperdave Jan 15, 2024
88d132e
ok
paperdave Jan 15, 2024
904db0d
yippee
paperdave Jan 15, 2024
ea4d610
run the formatter back
paperdave Jan 15, 2024
d1d9e5f
finish things up
paperdave Jan 15, 2024
436daef
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Jan 15, 2024
52d60f9
fix webkit
paperdave Jan 15, 2024
a6dcca8
more
paperdave Jan 15, 2024
a919705
Merge branch 'main' into dave/hide-internals
Jarred-Sumner Jan 16, 2024
837713d
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Jan 16, 2024
e0a808a
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 16, 2024
3e42c02
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Feb 8, 2024
678cc3f
fix compile
paperdave Feb 8, 2024
c52d834
fix compilation on windows, it seems to not work though :(
paperdave Feb 9, 2024
37835a2
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 7, 2024
99cdf7f
update
paperdave Mar 7, 2024
e21a059
a
paperdave Mar 7, 2024
143f3a4
v
paperdave Mar 7, 2024
a54e64d
ok
paperdave Mar 8, 2024
e50c429
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 8, 2024
fb87d59
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 8, 2024
83e480b
OOPS
paperdave Mar 8, 2024
f66f3e3
bump bun to reduce ci bugs
paperdave Mar 8, 2024
9e98673
a
paperdave Mar 9, 2024
7b146fc
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 11, 2024
87654b9
js2native is done!
paperdave Mar 11, 2024
b8452b3
improve array binding
paperdave Mar 11, 2024
7bdd818
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 14, 2024
2aaefdc
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 14, 2024
a703fc5
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 28, 2024
7dc6b51
rebase
paperdave Mar 28, 2024
3e9df89
Merge remote-tracking branch 'origin/main' into dave/hide-internals
paperdave Mar 29, 2024
76fd2ba
some final stuff
paperdave Mar 29, 2024
4b548c9
Merge branch 'main' into dave/hide-internals
paperdave Mar 29, 2024
a893d86
wasi fixes
paperdave Mar 30, 2024
eb6d07b
os
paperdave Mar 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/bun-linux-build.yml
Expand Up @@ -277,6 +277,7 @@ jobs:
SMTP_SENDGRID_SENDER: ${{ secrets.SMTP_SENDGRID_SENDER }}
TLS_MONGODB_DATABASE_URL: ${{ secrets.TLS_MONGODB_DATABASE_URL }}
TLS_POSTGRES_DATABASE_URL: ${{ secrets.TLS_POSTGRES_DATABASE_URL }}
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "true"
# if: ${{github.event.inputs.use_bun == 'false'}}
run: |
ulimit -c unlimited
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bun-mac-aarch64.yml
Expand Up @@ -428,6 +428,7 @@ jobs:
SMTP_SENDGRID_SENDER: ${{ secrets.SMTP_SENDGRID_SENDER }}
TLS_MONGODB_DATABASE_URL: ${{ secrets.TLS_MONGODB_DATABASE_URL }}
TLS_POSTGRES_DATABASE_URL: ${{ secrets.TLS_POSTGRES_DATABASE_URL }}
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "true"
# if: ${{github.event.inputs.use_bun == 'false'}}
run: |
node packages/bun-internal-test/src/runner.node.mjs || true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bun-mac-x64-baseline.yml
Expand Up @@ -430,6 +430,7 @@ jobs:
SMTP_SENDGRID_SENDER: ${{ secrets.SMTP_SENDGRID_SENDER }}
TLS_MONGODB_DATABASE_URL: ${{ secrets.TLS_MONGODB_DATABASE_URL }}
TLS_POSTGRES_DATABASE_URL: ${{ secrets.TLS_POSTGRES_DATABASE_URL }}
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "true"
# if: ${{github.event.inputs.use_bun == 'false'}}
run: |
node packages/bun-internal-test/src/runner.node.mjs || true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bun-mac-x64.yml
Expand Up @@ -427,6 +427,7 @@ jobs:
SMTP_SENDGRID_SENDER: ${{ secrets.SMTP_SENDGRID_SENDER }}
TLS_MONGODB_DATABASE_URL: ${{ secrets.TLS_MONGODB_DATABASE_URL }}
TLS_POSTGRES_DATABASE_URL: ${{ secrets.TLS_POSTGRES_DATABASE_URL }}
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "true"
# if: ${{github.event.inputs.use_bun == 'false'}}
run: |
node packages/bun-internal-test/src/runner.node.mjs || true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bun-windows.yml
Expand Up @@ -413,6 +413,7 @@ jobs:
SMTP_SENDGRID_SENDER: ${{ secrets.SMTP_SENDGRID_SENDER }}
TLS_MONGODB_DATABASE_URL: ${{ secrets.TLS_MONGODB_DATABASE_URL }}
TLS_POSTGRES_DATABASE_URL: ${{ secrets.TLS_POSTGRES_DATABASE_URL }}
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "true"
run: |
try {
$ErrorActionPreference = "SilentlyContinue"
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -163,4 +163,6 @@ x64

**/.verdaccio-db.json
/test-report.md
/test-report.json
/test-report.json

/src/bun.js/bindings/GeneratedJS2Native.zig
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Expand Up @@ -54,6 +54,7 @@
"name": "BunWithJSCDebug",
"forcedInclude": ["${workspaceFolder}/src/bun.js/bindings/root.h"],
"includePath": [
"${workspaceFolder}/build/codegen",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/ICU/Headers/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/JavaScriptCore/PrivateHeaders/",
Expand Down
12 changes: 3 additions & 9 deletions CMakeLists.txt
Expand Up @@ -693,10 +693,12 @@ if(NOT NO_CODEGEN)
"${BUN_WORKDIR}/codegen/NativeModuleImpl.h"
"${BUN_WORKDIR}/codegen/ResolvedSourceTag.zig"
"${BUN_WORKDIR}/codegen/SyntheticModuleType.h"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.h"
COMMAND ${BUN_EXECUTABLE} "${BUN_SRC}/codegen/bundle-modules.ts" "--debug=${DEBUG}" "${BUN_WORKDIR}"
DEPENDS ${BUN_TS_MODULES} ${CODEGEN_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Bundling JS modules"
COMMENT "Bundling JS"
)
endif()

Expand All @@ -705,14 +707,6 @@ WEBKIT_ADD_SOURCE_DEPENDENCIES(
"${BUN_WORKDIR}/codegen/InternalModuleRegistryConstants.h"
)

add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.h"
COMMAND ${BUN_EXECUTABLE} "${BUN_SRC}/codegen/bundle-functions.ts" "--debug=${DEBUG}" "${BUN_WORKDIR}"
DEPENDS ${BUN_TS_FUNCTIONS} ${CODEGEN_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Bundling JS builtin functions"
)
list(APPEND BUN_RAW_SOURCES "${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp")

# --- Peechy API ---
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/WebKit
Submodule WebKit updated 0 files
83 changes: 4 additions & 79 deletions src/bun.js/api/bun.zig → src/bun.js/api/BunObject.zig
Expand Up @@ -8,19 +8,13 @@
/// - Run "make dev"
pub const BunObject = struct {
// --- Callbacks ---
pub const DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump = dump_mimalloc;
pub const _Os = Bun._Os;
pub const _Path = Bun._Path;
pub const allocUnsafe = Bun.allocUnsafe;
pub const build = Bun.JSBundler.buildFn;
pub const connect = JSC.wrapStaticMethod(JSC.API.Listener, "connect", false);
pub const deflateSync = JSC.wrapStaticMethod(JSZlib, "deflateSync", true);
pub const file = WebCore.Blob.constructBunFile;
pub const fs = Bun.fs;
pub const gc = Bun.runGC;
pub const generateHeapSnapshot = Bun.generateHeapSnapshot;
pub const getImportedStyles = Bun.getImportedStyles;
pub const getPublicPath = Bun.getPublicPathJS;
pub const gunzipSync = JSC.wrapStaticMethod(JSZlib, "gunzipSync", true);
pub const gzipSync = JSC.wrapStaticMethod(JSZlib, "gzipSync", true);
pub const indexOfLine = Bun.indexOfLine;
Expand Down Expand Up @@ -121,18 +115,13 @@ pub const BunObject = struct {
// --- Getters --

// -- Callbacks --
@export(BunObject.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump, .{ .name = callbackName("DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump") });
@export(BunObject._Os, .{ .name = callbackName("_Os") });
@export(BunObject._Path, .{ .name = callbackName("_Path") });
@export(BunObject.allocUnsafe, .{ .name = callbackName("allocUnsafe") });
@export(BunObject.build, .{ .name = callbackName("build") });
@export(BunObject.connect, .{ .name = callbackName("connect") });
@export(BunObject.deflateSync, .{ .name = callbackName("deflateSync") });
@export(BunObject.file, .{ .name = callbackName("file") });
@export(BunObject.fs, .{ .name = callbackName("fs") });
@export(BunObject.gc, .{ .name = callbackName("gc") });
@export(BunObject.generateHeapSnapshot, .{ .name = callbackName("generateHeapSnapshot") });
@export(BunObject.getImportedStyles, .{ .name = callbackName("getImportedStyles") });
@export(BunObject.gunzipSync, .{ .name = callbackName("gunzipSync") });
@export(BunObject.gzipSync, .{ .name = callbackName("gzipSync") });
@export(BunObject.indexOfLine, .{ .name = callbackName("indexOfLine") });
Expand Down Expand Up @@ -952,41 +941,9 @@ pub fn getPublicPathJS(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFr
return ZigString.init(stream.buffer[0..stream.pos]).toValueGC(globalObject);
}

fn fs(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
var module = globalObject.allocator().create(JSC.Node.NodeJSFS) catch unreachable;
module.* = .{};
const vm = globalObject.bunVM();
if (vm.standalone_module_graph != null)
module.node_fs.vm = vm;

return module.toJS(globalObject);
}

fn _Os(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return Node.Os.create(globalObject);
}

fn _Path(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
const arguments = callframe.arguments(1);
const args = arguments.slice();
const is_windows = args.len == 1 and args[0].toBoolean();
return Node.Path.create(globalObject, is_windows);
}

/// @deprecated
fn getImportedStyles(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
defer flushCSSImports();
const styles = getCSSImports();
if (styles.len == 0) {
return JSC.JSValue.createEmptyArray(globalObject, 0);
}

return JSValue.createStringArray(globalObject, styles.ptr, styles.len, true);
}

extern fn dump_zone_malloc_stats() void;

pub fn dump_mimalloc(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
export fn dump_mimalloc(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
globalObject.bunVM().arena.dumpStats();
if (comptime bun.is_heap_breakdown_enabled) {
dump_zone_malloc_stats();
Expand Down Expand Up @@ -3035,6 +2992,7 @@ const UnsafeObject = struct {
.gcAggressionLevel = &gcAggressionLevel,
.segfault = &__debug__doSegfault,
.arrayBufferToString = &arrayBufferToString,
.mimallocDump = &dump_mimalloc,
};
inline for (comptime std.meta.fieldNames(@TypeOf(fields))) |name| {
object.put(
Expand Down Expand Up @@ -4925,40 +4883,7 @@ pub const JSZlib = struct {

pub usingnamespace @import("./bun/subprocess.zig");

const InternalTestingAPIs = struct {
pub fn BunInternalFunction__syntaxHighlighter(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
const args = callframe.arguments(1);
if (args.len < 1) {
globalThis.throwNotEnoughArguments("code", 1, 0);
}

const code = args.ptr[0].toSliceOrNull(globalThis) orelse return .zero;
defer code.deinit();
var buffer = MutableString.initEmpty(bun.default_allocator);
defer buffer.deinit();
var writer = buffer.bufferedWriter();
var formatter = bun.fmt.fmtJavaScript(code.slice(), true);
formatter.limited = false;
std.fmt.format(writer.writer(), "{}", .{formatter}) catch |err| {
globalThis.throwError(err, "Error formatting code");
return .zero;
};

writer.flush() catch |err| {
globalThis.throwError(err, "Error formatting code");
return .zero;
};

var str = bun.String.create(buffer.list.items);
defer str.deref();
return str.toJS(globalThis);
}
};

comptime {
if (!JSC.is_bindgen) {
_ = Crypto.JSPasswordObject.JSPasswordObject__create;
BunObject.exportAll();
@export(InternalTestingAPIs.BunInternalFunction__syntaxHighlighter, .{ .name = "BunInternalFunction__syntaxHighlighter" });
}
_ = Crypto.JSPasswordObject.JSPasswordObject__create;
BunObject.exportAll();
}
17 changes: 10 additions & 7 deletions src/bun.js/api/bun/h2_frame_parser.zig
Expand Up @@ -253,7 +253,7 @@ const SingleValueHeaders = bun.ComptimeStringMap(void, .{
.{"x-content-type-options"},
});

pub export fn BUN__HTTP2__getUnpackedSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
pub fn jsGetUnpackedSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());
var settings: FullSettingsPayload = .{};

Expand Down Expand Up @@ -288,7 +288,7 @@ pub export fn BUN__HTTP2__getUnpackedSettings(globalObject: *JSC.JSGlobalObject,
}
}

pub export fn BUN__HTTP2_getPackedSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSValue {
pub fn jsGetPackedSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
var settings: FullSettingsPayload = .{};
const args_list = callframe.arguments(1);

Expand Down Expand Up @@ -400,11 +400,6 @@ pub export fn BUN__HTTP2_getPackedSettings(globalObject: *JSC.JSGlobalObject, ca
return binary_type.toJS(bytes, globalObject);
}

comptime {
_ = BUN__HTTP2__getUnpackedSettings;
_ = BUN__HTTP2_getPackedSettings;
}

const Handlers = struct {
onError: JSC.JSValue = .zero,
onWrite: JSC.JSValue = .zero,
Expand Down Expand Up @@ -2539,3 +2534,11 @@ pub const H2FrameParser = struct {
this.deinit();
}
};

pub fn createNodeHttp2Binding(global: *JSC.JSGlobalObject) JSC.JSValue {
return JSC.JSArray.createComptime(global, .{
paperdave marked this conversation as resolved.
Show resolved Hide resolved
H2FrameParser.getConstructor(global),
JSC.JSFunction.create(global, "getPackedSettings", jsGetPackedSettings, 0, .{}),
JSC.JSFunction.create(global, "getUnpackedSettings", jsGetUnpackedSettings, 0, .{}),
});
}
4 changes: 0 additions & 4 deletions src/bun.js/bindings/BunObject+exports.h
Expand Up @@ -32,9 +32,6 @@

// --- Callbacks ---
#define FOR_EACH_CALLBACK(macro) \
macro(DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump) \
macro(_Os) \
macro(_Path) \
macro(allocUnsafe) \
macro(build) \
macro(connect) \
Expand All @@ -43,7 +40,6 @@
macro(fs) \
macro(gc) \
macro(generateHeapSnapshot) \
macro(getImportedStyles) \
macro(gunzipSync) \
macro(gzipSync) \
macro(indexOfLine) \
Expand Down
20 changes: 0 additions & 20 deletions src/bun.js/bindings/BunObject.cpp
Expand Up @@ -486,24 +486,10 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
return JSC::JSValue::encode(JSC::jsString(vm, url.fileSystemPath()));
}

JSC_DEFINE_HOST_FUNCTION(functionHashCode,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::JSValue stringToHash = callFrame->argument(0);
JSC::JSString* str = stringToHash.toStringOrNull(globalObject);
if (!str) {
return JSC::JSValue::encode(jsNumber(0));
}

auto view = str->value(globalObject);
return JSC::JSValue::encode(jsNumber(view.hash()));
}

/* Source for BunObject.lut.h
@begin bunObjectTable
ArrayBufferSink BunObject_getter_wrap_ArrayBufferSink DontDelete|PropertyCallback
CryptoHasher BunObject_getter_wrap_CryptoHasher DontDelete|PropertyCallback
DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump BunObject_callback_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump DontEnum|DontDelete|Function 1
FFI BunObject_getter_wrap_FFI DontDelete|PropertyCallback
FileSystemRouter BunObject_getter_wrap_FileSystemRouter DontDelete|PropertyCallback
Glob BunObject_getter_wrap_Glob DontDelete|PropertyCallback
Expand All @@ -517,11 +503,8 @@ JSC_DEFINE_HOST_FUNCTION(functionHashCode,
SHA512_256 BunObject_getter_wrap_SHA512_256 DontDelete|PropertyCallback
TOML BunObject_getter_wrap_TOML DontDelete|PropertyCallback
Transpiler BunObject_getter_wrap_Transpiler DontDelete|PropertyCallback
_Os BunObject_callback__Os DontEnum|DontDelete|Function 1
_Path BunObject_callback__Path DontEnum|DontDelete|Function 1
allocUnsafe BunObject_callback_allocUnsafe DontDelete|Function 1
argv BunObject_getter_wrap_argv DontDelete|PropertyCallback
assetPrefix BunObject_getter_wrap_assetPrefix DontEnum|DontDelete|PropertyCallback
build BunObject_callback_build DontDelete|Function 1
concatArrayBuffers functionConcatTypedArrays DontDelete|Function 1
connect BunObject_callback_connect DontDelete|Function 1
Expand All @@ -536,10 +519,8 @@ JSC_DEFINE_HOST_FUNCTION(functionHashCode,
fetch Bun__fetch ReadOnly|DontDelete|Function 1
file BunObject_callback_file DontDelete|Function 1
fileURLToPath functionFileURLToPath DontDelete|Function 1
fs BunObject_callback_fs DontEnum|DontDelete|Function 1
gc BunObject_callback_gc DontDelete|Function 1
generateHeapSnapshot BunObject_callback_generateHeapSnapshot DontDelete|Function 1
getImportedStyles BunObject_callback_getImportedStyles DontEnum|DontDelete|Function 1
gunzipSync BunObject_callback_gunzipSync DontDelete|Function 1
gzipSync BunObject_callback_gzipSync DontDelete|Function 1
hash BunObject_getter_wrap_hash DontDelete|PropertyCallback
Expand Down Expand Up @@ -579,7 +560,6 @@ JSC_DEFINE_HOST_FUNCTION(functionHashCode,
stderr BunObject_getter_wrap_stderr DontDelete|PropertyCallback
stdin BunObject_getter_wrap_stdin DontDelete|PropertyCallback
stdout BunObject_getter_wrap_stdout DontDelete|PropertyCallback
stringHashCode functionHashCode DontDelete|Function 1
unsafe BunObject_getter_wrap_unsafe DontDelete|PropertyCallback
version constructBunVersion ReadOnly|DontDelete|PropertyCallback
which BunObject_callback_which DontDelete|Function 1
Expand Down