mirror of
https://github.com/oven-sh/bun
synced 2026-02-04 07:58:54 +00:00
Compare commits
1 Commits
dylan/pyth
...
jarred/ren
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3fb83513a |
@@ -869,7 +869,7 @@ pub fn resolve(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun
|
||||
const err = globalObject.takeError(e);
|
||||
return jsc.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(globalObject, err);
|
||||
};
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalObject, value);
|
||||
return jsc.JSPromise.createResolved(globalObject, value);
|
||||
}
|
||||
|
||||
export fn Bun__resolve(global: *JSGlobalObject, specifier: JSValue, source: JSValue, is_esm: bool) jsc.JSValue {
|
||||
@@ -884,7 +884,7 @@ export fn Bun__resolve(global: *JSGlobalObject, specifier: JSValue, source: JSVa
|
||||
return jsc.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(global, err);
|
||||
};
|
||||
|
||||
return jsc.JSPromise.resolvedPromiseValue(global, value);
|
||||
return jsc.JSPromise.createResolved(global, value);
|
||||
}
|
||||
|
||||
export fn Bun__resolveSync(global: *JSGlobalObject, specifier: JSValue, source: JSValue, is_esm: bool, is_user_require_resolve: bool) jsc.JSValue {
|
||||
|
||||
@@ -847,10 +847,10 @@ pub fn getExited(
|
||||
|
||||
switch (this.process.status) {
|
||||
.exited => |exit| {
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(exit.code));
|
||||
return jsc.JSPromise.createResolved(globalThis, JSValue.jsNumber(exit.code));
|
||||
},
|
||||
.signaled => |signal| {
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(signal.toExitCode() orelse 254));
|
||||
return jsc.JSPromise.createResolved(globalThis, JSValue.jsNumber(signal.toExitCode() orelse 254));
|
||||
},
|
||||
.err => |err| {
|
||||
return jsc.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(globalThis, err.toJS(globalThis));
|
||||
|
||||
@@ -355,7 +355,7 @@ pub const UDPSocket = struct {
|
||||
const thisValue = this.toJS(globalThis);
|
||||
thisValue.ensureStillAlive();
|
||||
this.thisValue = thisValue;
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, thisValue);
|
||||
return jsc.JSPromise.createResolved(globalThis, thisValue);
|
||||
}
|
||||
|
||||
pub fn callErrorHandler(
|
||||
|
||||
@@ -693,12 +693,12 @@ pub const JSPasswordObject = struct {
|
||||
|
||||
if (owned_hash.len == 0) {
|
||||
bun.default_allocator.free(owned_password);
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalObject, .false);
|
||||
return jsc.JSPromise.createResolved(globalObject, .false);
|
||||
}
|
||||
|
||||
if (owned_password.len == 0) {
|
||||
bun.default_allocator.free(owned_hash);
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalObject, .false);
|
||||
return jsc.JSPromise.createResolved(globalObject, .false);
|
||||
}
|
||||
|
||||
return verify(globalObject, owned_password, owned_hash, algorithm, false);
|
||||
|
||||
@@ -1241,7 +1241,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
if (response_value.as(jsc.WebCore.Response)) |resp| {
|
||||
resp.url = existing_request.url.clone();
|
||||
}
|
||||
return jsc.JSPromise.resolvedPromiseValue(ctx, response_value);
|
||||
return jsc.JSPromise.createResolved(ctx, response_value);
|
||||
}
|
||||
|
||||
pub fn closeIdleConnections(this: *ThisServer, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
|
||||
|
||||
@@ -11,7 +11,7 @@ pub const JSPromise = opaque {
|
||||
/// meaning it will not trigger unhandled rejection handling. Use JSC__JSPromise__rejectedPromise instead.
|
||||
extern fn JSC__JSPromise__rejectedPromiseValue(arg0: *JSGlobalObject, JSValue1: JSValue) JSValue;
|
||||
extern fn JSC__JSPromise__resolvedPromise(arg0: *JSGlobalObject, JSValue1: JSValue) *JSPromise;
|
||||
extern fn JSC__JSPromise__resolvedPromiseValue(arg0: *JSGlobalObject, JSValue1: JSValue) JSValue;
|
||||
extern fn JSC__JSPromise__createResolved(arg0: *JSGlobalObject, JSValue1: JSValue) JSValue;
|
||||
extern fn JSC__JSPromise__wrap(*jsc.JSGlobalObject, *anyopaque, *const fn (*anyopaque, *jsc.JSGlobalObject) callconv(.C) jsc.JSValue) jsc.JSValue;
|
||||
|
||||
pub fn Weak(comptime T: type) type {
|
||||
@@ -188,9 +188,9 @@ pub const JSPromise = opaque {
|
||||
|
||||
pub fn wrapValue(globalObject: *JSGlobalObject, value: JSValue) JSValue {
|
||||
if (value == .zero) {
|
||||
return resolvedPromiseValue(globalObject, .js_undefined);
|
||||
return createResolved(globalObject, .js_undefined);
|
||||
} else if (value.isEmptyOrUndefinedOrNull() or !value.isCell()) {
|
||||
return resolvedPromiseValue(globalObject, value);
|
||||
return createResolved(globalObject, value);
|
||||
}
|
||||
|
||||
if (value.jsType() == .JSPromise) {
|
||||
@@ -201,7 +201,7 @@ pub const JSPromise = opaque {
|
||||
return dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(globalObject, value);
|
||||
}
|
||||
|
||||
return resolvedPromiseValue(globalObject, value);
|
||||
return createResolved(globalObject, value);
|
||||
}
|
||||
|
||||
pub fn status(this: *const JSPromise, vm: *VM) Status {
|
||||
@@ -226,8 +226,8 @@ pub const JSPromise = opaque {
|
||||
|
||||
/// Create a new promise with an already fulfilled value
|
||||
/// This is the faster function for doing that.
|
||||
pub fn resolvedPromiseValue(globalThis: *JSGlobalObject, value: JSValue) JSValue {
|
||||
return JSC__JSPromise__resolvedPromiseValue(globalThis, value);
|
||||
pub fn createResolved(globalThis: *JSGlobalObject, value: JSValue) JSValue {
|
||||
return JSC__JSPromise__createResolved(globalThis, value);
|
||||
}
|
||||
|
||||
pub fn rejectedPromise(globalThis: *JSGlobalObject, value: JSValue) *JSPromise {
|
||||
@@ -244,7 +244,7 @@ pub const JSPromise = opaque {
|
||||
|
||||
/// Fulfill an existing promise with the value
|
||||
/// The value can be another Promise
|
||||
/// If you want to create a new Promise that is already resolved, see JSPromise.resolvedPromiseValue
|
||||
/// If you want to create a new Promise that is already resolved, see JSPromise.createResolved
|
||||
pub fn resolve(this: *JSPromise, globalThis: *JSGlobalObject, value: JSValue) void {
|
||||
if (comptime bun.Environment.isDebug) {
|
||||
const loop = jsc.VirtualMachine.get().eventLoop();
|
||||
|
||||
@@ -5533,7 +5533,7 @@ JSC::EncodedJSValue JSC__JSPromise__rejectedPromiseValue(JSC::JSGlobalObject* gl
|
||||
return JSC::JSValue::encode(promise);
|
||||
}
|
||||
|
||||
JSC::EncodedJSValue JSC__JSPromise__resolvedPromiseValue(JSC::JSGlobalObject* globalObject,
|
||||
JSC::EncodedJSValue JSC__JSPromise__createResolved(JSC::JSGlobalObject* globalObject,
|
||||
JSC::EncodedJSValue JSValue1)
|
||||
{
|
||||
auto& vm = JSC::getVM(globalObject);
|
||||
|
||||
2
src/bun.js/bindings/headers.h
generated
2
src/bun.js/bindings/headers.h
generated
@@ -145,7 +145,7 @@ CPP_DECL JSC::EncodedJSValue JSC__JSPromise__rejectedPromiseValue(JSC::JSGlobalO
|
||||
CPP_DECL void JSC__JSPromise__rejectOnNextTickWithHandled(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue JSValue2, bool arg3);
|
||||
CPP_DECL void JSC__JSPromise__resolve(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue JSValue2);
|
||||
CPP_DECL JSC::JSPromise* JSC__JSPromise__resolvedPromise(JSC::JSGlobalObject* arg0, JSC::EncodedJSValue JSValue1);
|
||||
CPP_DECL JSC::EncodedJSValue JSC__JSPromise__resolvedPromiseValue(JSC::JSGlobalObject* arg0, JSC::EncodedJSValue JSValue1);
|
||||
CPP_DECL JSC::EncodedJSValue JSC__JSPromise__createResolved(JSC::JSGlobalObject* arg0, JSC::EncodedJSValue JSValue1);
|
||||
CPP_DECL JSC::EncodedJSValue JSC__JSPromise__result(JSC::JSPromise* arg0, JSC::VM* arg1);
|
||||
CPP_DECL void JSC__JSPromise__setHandled(JSC::JSPromise* arg0, JSC::VM* arg1);
|
||||
CPP_DECL uint32_t JSC__JSPromise__status(const JSC::JSPromise* arg0, JSC::VM* arg1);
|
||||
|
||||
@@ -40,11 +40,9 @@ pub threadlocal var global: *MiniEventLoop = undefined;
|
||||
|
||||
pub const ConcurrentTaskQueue = UnboundedQueue(AnyTaskWithExtraContext, .next);
|
||||
|
||||
pub fn initGlobal(env: ?*bun.DotEnv.Loader, cwd: ?[]const u8) *MiniEventLoop {
|
||||
pub fn initGlobal(env: ?*bun.DotEnv.Loader, cwd: []const u8) *MiniEventLoop {
|
||||
if (globalInitialized) return global;
|
||||
const loop = MiniEventLoop.init(bun.default_allocator);
|
||||
global = bun.handleOom(bun.default_allocator.create(MiniEventLoop));
|
||||
global.* = loop;
|
||||
global = bun.new(MiniEventLoop, MiniEventLoop.init(bun.default_allocator));
|
||||
global.loop.internal_loop_data.setParentEventLoop(bun.jsc.EventLoopHandle.init(global));
|
||||
global.env = env orelse bun.DotEnv.instance orelse env_loader: {
|
||||
const map = bun.handleOom(bun.default_allocator.create(bun.DotEnv.Map));
|
||||
@@ -54,22 +52,6 @@ pub fn initGlobal(env: ?*bun.DotEnv.Loader, cwd: ?[]const u8) *MiniEventLoop {
|
||||
loader.* = bun.DotEnv.Loader.init(map, bun.default_allocator);
|
||||
break :env_loader loader;
|
||||
};
|
||||
|
||||
// Set top_level_dir from provided cwd or get current working directory
|
||||
if (cwd) |dir| {
|
||||
global.top_level_dir = dir;
|
||||
} else if (global.top_level_dir.len == 0) {
|
||||
var buf: bun.PathBuffer = undefined;
|
||||
switch (bun.sys.getcwd(&buf)) {
|
||||
.result => |p| {
|
||||
global.top_level_dir = bun.default_allocator.dupe(u8, p) catch "";
|
||||
},
|
||||
.err => {
|
||||
global.top_level_dir = "";
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
globalInitialized = true;
|
||||
return global;
|
||||
}
|
||||
|
||||
@@ -912,7 +912,7 @@ fn writeFileWithEmptySourceToDestination(ctx: *jsc.JSGlobalObject, destination_b
|
||||
},
|
||||
.result => |fd| {
|
||||
fd.close();
|
||||
return jsc.JSPromise.resolvedPromiseValue(ctx, .jsNumber(0));
|
||||
return jsc.JSPromise.createResolved(ctx, .jsNumber(0));
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -982,7 +982,7 @@ fn writeFileWithEmptySourceToDestination(ctx: *jsc.JSGlobalObject, destination_b
|
||||
.bytes => {},
|
||||
}
|
||||
|
||||
return jsc.JSPromise.resolvedPromiseValue(ctx, jsc.JSValue.jsNumber(0));
|
||||
return jsc.JSPromise.createResolved(ctx, jsc.JSValue.jsNumber(0));
|
||||
}
|
||||
|
||||
pub fn writeFileWithSourceDestination(ctx: *jsc.JSGlobalObject, source_blob: *Blob, destination_blob: *Blob, options: WriteFileOptions) bun.JSError!jsc.JSValue {
|
||||
@@ -1080,11 +1080,11 @@ pub fn writeFileWithSourceDestination(ctx: *jsc.JSGlobalObject, source_blob: *Bl
|
||||
clone.allocator = bun.default_allocator;
|
||||
const cloned = Blob.new(clone);
|
||||
cloned.allocator = bun.default_allocator;
|
||||
return JSPromise.resolvedPromiseValue(ctx, cloned.toJS(ctx));
|
||||
return JSPromise.createResolved(ctx, cloned.toJS(ctx));
|
||||
} else if (destination_type == .bytes and (source_type == .file or source_type == .s3)) {
|
||||
const blob_value = source_blob.getSliceFrom(ctx, 0, 0, "", false);
|
||||
|
||||
return JSPromise.resolvedPromiseValue(
|
||||
return JSPromise.createResolved(
|
||||
ctx,
|
||||
blob_value,
|
||||
);
|
||||
@@ -1624,7 +1624,7 @@ fn writeStringToFileFast(
|
||||
}
|
||||
}
|
||||
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, jsc.JSValue.jsNumber(written));
|
||||
return jsc.JSPromise.createResolved(globalThis, jsc.JSValue.jsNumber(written));
|
||||
}
|
||||
|
||||
fn writeBytesToFileFast(
|
||||
@@ -1711,7 +1711,7 @@ fn writeBytesToFileFast(
|
||||
}
|
||||
}
|
||||
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, jsc.JSValue.jsNumber(written));
|
||||
return jsc.JSPromise.createResolved(globalThis, jsc.JSValue.jsNumber(written));
|
||||
}
|
||||
export fn JSDOMFile__construct(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) callconv(jsc.conv) ?*Blob {
|
||||
return JSDOMFile__construct_(globalThis, callframe) catch |err| switch (err) {
|
||||
@@ -2330,7 +2330,7 @@ pub fn getExists(
|
||||
if (this.isS3()) {
|
||||
return S3File.S3BlobStatTask.exists(globalThis, this);
|
||||
}
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, this.getExistsSync());
|
||||
return jsc.JSPromise.createResolved(globalThis, this.getExistsSync());
|
||||
}
|
||||
|
||||
pub const FileStreamWrapper = struct {
|
||||
@@ -2570,7 +2570,7 @@ pub fn pipeReadableStreamToBlob(this: *Blob, globalThis: *jsc.JSGlobalObject, re
|
||||
.fulfilled => {
|
||||
file_sink.deref();
|
||||
readable_stream.done(globalThis);
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, jsc.JSValue.jsNumber(0));
|
||||
return jsc.JSPromise.createResolved(globalThis, jsc.JSValue.jsNumber(0));
|
||||
},
|
||||
.rejected => {
|
||||
file_sink.deref();
|
||||
@@ -2590,7 +2590,7 @@ pub fn pipeReadableStreamToBlob(this: *Blob, globalThis: *jsc.JSGlobalObject, re
|
||||
}
|
||||
file_sink.deref();
|
||||
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalThis, jsc.JSValue.jsNumber(0));
|
||||
return jsc.JSPromise.createResolved(globalThis, jsc.JSValue.jsNumber(0));
|
||||
}
|
||||
|
||||
pub fn getWriter(
|
||||
|
||||
@@ -1312,7 +1312,7 @@ pub fn Mixin(comptime Type: type) type {
|
||||
blob.store.?.mime_type = MimeType.text;
|
||||
}
|
||||
}
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalObject, blob.toJS(globalObject));
|
||||
return jsc.JSPromise.createResolved(globalObject, blob.toJS(globalObject));
|
||||
}
|
||||
|
||||
pub fn getBlobWithoutCallFrame(this: *Type, globalObject: *jsc.JSGlobalObject) bun.JSError!jsc.JSValue {
|
||||
|
||||
@@ -267,7 +267,7 @@ pub const File = struct {
|
||||
},
|
||||
},
|
||||
}, globalThis.bunVM()),
|
||||
.fd => jsc.JSPromise.resolvedPromiseValue(globalThis, globalThis.createInvalidArgs("Is not possible to unlink a file descriptor", .{})),
|
||||
.fd => jsc.JSPromise.createResolved(globalThis, globalThis.createInvalidArgs("Is not possible to unlink a file descriptor", .{})),
|
||||
};
|
||||
}
|
||||
pub fn isSeekable(this: *const File) ?bool {
|
||||
|
||||
@@ -1411,7 +1411,7 @@ fn dataURLResponse(
|
||||
},
|
||||
);
|
||||
|
||||
return JSPromise.resolvedPromiseValue(globalThis, response.toJS(globalThis));
|
||||
return JSPromise.createResolved(globalThis, response.toJS(globalThis));
|
||||
}
|
||||
|
||||
comptime {
|
||||
@@ -2332,7 +2332,7 @@ pub fn Bun__fetch_(
|
||||
.url = url_string.clone(),
|
||||
});
|
||||
|
||||
return JSPromise.resolvedPromiseValue(globalThis, response.toJS(globalThis));
|
||||
return JSPromise.createResolved(globalThis, response.toJS(globalThis));
|
||||
}
|
||||
|
||||
if (url.protocol.len > 0) {
|
||||
|
||||
@@ -957,7 +957,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
|
||||
}
|
||||
|
||||
if (this.buffer.len == 0 or this.done) {
|
||||
return .{ .result = jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumberFromInt32(0)) };
|
||||
return .{ .result = jsc.JSPromise.createResolved(globalThis, JSValue.jsNumberFromInt32(0)) };
|
||||
}
|
||||
|
||||
if (!this.hasBackpressureAndIsTryEnd()) {
|
||||
@@ -965,7 +965,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
|
||||
assert(slice.len > 0);
|
||||
const success = this.send(slice);
|
||||
if (success) {
|
||||
return .{ .result = jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(slice.len)) };
|
||||
return .{ .result = jsc.JSPromise.createResolved(globalThis, JSValue.jsNumber(slice.len)) };
|
||||
}
|
||||
}
|
||||
this.wrote_at_start_of_flush = this.wrote;
|
||||
@@ -1413,7 +1413,7 @@ pub const NetworkSink = struct {
|
||||
|
||||
// nothing todo here
|
||||
if (this.done) {
|
||||
return .{ .result = jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(0)) };
|
||||
return .{ .result = jsc.JSPromise.createResolved(globalThis, JSValue.jsNumber(0)) };
|
||||
}
|
||||
// flush more
|
||||
if (this.task) |task| {
|
||||
@@ -1424,7 +1424,7 @@ pub const NetworkSink = struct {
|
||||
}
|
||||
}
|
||||
// we are done flushing no backpressure
|
||||
return .{ .result = jsc.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(0)) };
|
||||
return .{ .result = jsc.JSPromise.createResolved(globalThis, JSValue.jsNumber(0)) };
|
||||
}
|
||||
pub fn finalizeAndDestroy(this: *@This()) void {
|
||||
this.finalize();
|
||||
|
||||
@@ -165,7 +165,7 @@ pub const JSValkeyClient = struct {
|
||||
|
||||
// If already connected, resolve immediately
|
||||
if (this.client.status == .connected) {
|
||||
return jsc.JSPromise.resolvedPromiseValue(globalObject, js.helloGetCached(this_value) orelse .js_undefined);
|
||||
return jsc.JSPromise.createResolved(globalObject, js.helloGetCached(this_value) orelse .js_undefined);
|
||||
}
|
||||
|
||||
if (js.connectionPromiseGetCached(this_value)) |promise| {
|
||||
|
||||
Reference in New Issue
Block a user