fix errors

Former-commit-id: ac66d6af52f6a2340c57a957bed078f94a8cf8ed
This commit is contained in:
Jarred Sumner
2021-08-02 21:22:58 -07:00
parent b6e19438ea
commit dbda84ff87
18 changed files with 1352 additions and 936 deletions

View File

@@ -139,9 +139,11 @@ void GlobalObject::installAPIGlobals(JSClassRef *globals, int count) {
JSC::Identifier GlobalObject::moduleLoaderResolve(JSGlobalObject *globalObject,
JSModuleLoader *loader, JSValue key,
JSValue referrer, JSValue origin) {
auto res = Zig__GlobalObject__resolve(globalObject, toZigString(key, globalObject),
referrer.isString() ? toZigString(referrer, globalObject)
: ZigStringEmpty);
ErrorableZigString res;
res.success = false;
Zig__GlobalObject__resolve(&res, globalObject, toZigString(key, globalObject),
referrer.isString() ? toZigString(referrer, globalObject)
: ZigStringEmpty);
if (res.success) {
return toIdentifier(res.result.value, globalObject);
@@ -164,9 +166,11 @@ JSC::JSInternalPromise *GlobalObject::moduleLoaderImportModule(JSGlobalObject *g
RETURN_IF_EXCEPTION(scope, promise->rejectWithCaughtException(globalObject, scope));
auto sourceURL = sourceOrigin.url();
auto resolved = Zig__GlobalObject__resolve(
globalObject, toZigString(moduleNameValue, globalObject),
sourceURL.isEmpty() ? ZigStringCwd : toZigString(sourceURL.fileSystemPath()));
ErrorableZigString resolved;
resolved.success = false;
Zig__GlobalObject__resolve(&resolved, globalObject, toZigString(moduleNameValue, globalObject),
sourceURL.isEmpty() ? ZigStringCwd
: toZigString(sourceURL.fileSystemPath()));
if (!resolved.success) {
throwException(scope, resolved.result.err, globalObject);
return promise->rejectWithCaughtException(globalObject, scope);
@@ -201,7 +205,8 @@ JSC::JSInternalPromise *GlobalObject::moduleLoaderFetch(JSGlobalObject *globalOb
res.result.err.code = 0;
res.result.err.ptr = nullptr;
Zig__GlobalObject__fetch(&res, globalObject, moduleKeyZig, ZigStringEmpty);
Zig__GlobalObject__fetch(&res, globalObject, moduleKeyZig,
Zig::toZigString(value1, globalObject));
if (!res.success) {
throwException(scope, res.result.err, globalObject);

View File

@@ -8,6 +8,7 @@
#include <JavaScriptCore/ExceptionScope.h>
#include <JavaScriptCore/FunctionConstructor.h>
#include <JavaScriptCore/Identifier.h>
#include <JavaScriptCore/IteratorOperations.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSCallbackObject.h>
@@ -33,12 +34,40 @@
#include <wtf/text/WTFString.h>
extern "C" {
#pragma mark - JSC::Exception
JSC__Exception *JSC__Exception__create(JSC__JSGlobalObject *arg0, JSC__JSObject *arg1,
unsigned char StackCaptureAction2) {
return JSC::Exception::create(arg0->vm(), JSC::JSValue(arg1),
StackCaptureAction2 == 0
? JSC::Exception::StackCaptureAction::CaptureStack
: JSC::Exception::StackCaptureAction::DoNotCaptureStack);
}
JSC__JSValue JSC__Exception__value(JSC__Exception *arg0) {
return JSC::JSValue::encode(arg0->value());
}
// #pragma mark - JSC::PropertyNameArray
// CPP_DECL size_t JSC__PropertyNameArray__length(JSC__PropertyNameArray* arg0);
// CPP_DECL const JSC__PropertyName*
// JSC__PropertyNameArray__next(JSC__PropertyNameArray* arg0, size_t arg1);
// CPP_DECL void JSC__PropertyNameArray__release(JSC__PropertyNameArray* arg0);
size_t JSC__JSObject__getArrayLength(JSC__JSObject *arg0) { return arg0->getArrayLength(); }
JSC__JSValue JSC__JSObject__getIndex(JSC__JSObject *arg0, JSC__JSGlobalObject *arg1,
uint32_t arg3) {
return JSC::JSValue::encode(arg0->getIndex(arg1, arg3));
}
JSC__JSValue JSC__JSObject__getDirect(JSC__JSObject *arg0, JSC__JSGlobalObject *arg1,
ZigString arg2) {
return JSC::JSValue::encode(arg0->getDirect(arg1->vm(), Zig::toIdentifier(arg2, arg1)));
}
void JSC__JSObject__putDirect(JSC__JSObject *arg0, JSC__JSGlobalObject *arg1, ZigString key,
JSC__JSValue value) {
auto prop = Zig::toIdentifier(key, arg1);
arg0->putDirect(arg1->vm(), prop, JSC::JSValue::decode(value));
}
#pragma mark - JSC::JSCell
@@ -138,7 +167,7 @@ static JSC::JSValue doLink(JSC__JSGlobalObject *globalObject, JSC::JSValue modul
}
JSC__JSValue JSC__JSGlobalObject__createAggregateError(JSC__JSGlobalObject *globalObject,
JSC__JSValue *errors, uint16_t errors_count,
void **errors, uint16_t errors_count,
ZigString arg3) {
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -154,8 +183,8 @@ JSC__JSValue JSC__JSGlobalObject__createAggregateError(JSC__JSGlobalObject *glob
errors_count))) {
for (uint16_t i = 0; i < errors_count; ++i) {
array->initializeIndexWithoutBarrier(initializationScope, i,
JSC::JSValue::decode(errors[i]));
array->initializeIndexWithoutBarrier(
initializationScope, i, JSC::JSValue(reinterpret_cast<JSC::JSCell *>(errors[i])));
}
}
}
@@ -165,9 +194,10 @@ JSC__JSValue JSC__JSGlobalObject__createAggregateError(JSC__JSGlobalObject *glob
}
JSC::Structure *errorStructure = globalObject->errorStructure(JSC::ErrorType::AggregateError);
return RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::createAggregateError(
globalObject, vm, errorStructure, array, message, options,
nullptr, JSC::TypeNothing, false)));
scope.release();
return JSC::JSValue::encode(JSC::createAggregateError(
globalObject, vm, errorStructure, array, message, options, nullptr, JSC::TypeNothing, false));
}
// static JSC::JSNativeStdFunction* resolverFunction;
// static JSC::JSNativeStdFunction* rejecterFunction;
@@ -177,6 +207,21 @@ JSC__JSValue ZigString__toValue(ZigString arg0, JSC__JSGlobalObject *arg1) {
return JSC::JSValue::encode(JSC::JSValue(JSC::jsOwnedString(arg1->vm(), Zig::toString(arg0))));
}
JSC__JSValue ZigString__toErrorInstance(const ZigString *str, JSC__JSGlobalObject *globalObject) {
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSC::JSValue message = Zig::toJSString(*str, globalObject);
JSC::JSValue options = JSC::jsUndefined();
JSC::Structure *errorStructure = globalObject->errorStructure();
JSC::JSObject *result =
JSC::ErrorInstance::create(globalObject, errorStructure, message, options);
RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::JSValue()));
scope.release();
return JSC::JSValue::encode(JSC::JSValue(result));
}
static JSC::EncodedJSValue resolverFunctionCallback(JSC::JSGlobalObject *globalObject,
JSC::CallFrame *callFrame) {
return JSC::JSValue::encode(doLink(globalObject, callFrame->argument(0)));
@@ -638,6 +683,33 @@ bool JSC__JSValue__isError(JSC__JSValue JSValue0) {
JSC::JSObject *obj = JSC::JSValue::decode(JSValue0).getObject();
return obj != nullptr && obj->isErrorInstance();
}
bool JSC__JSValue__isAggregateError(JSC__JSValue JSValue0, JSC__JSGlobalObject *global) {
JSC::JSObject *obj = JSC::JSValue::decode(JSValue0).getObject();
if (obj != nullptr) {
if (JSC::ErrorInstance *err = JSC::jsDynamicCast<JSC::ErrorInstance *>(global->vm(), obj)) {
return err->errorType() == JSC::ErrorType::AggregateError;
}
}
return false;
}
bool JSC__JSValue__isIterable(JSC__JSValue JSValue, JSC__JSGlobalObject *global) {
return JSC::hasIteratorMethod(global, JSC::JSValue::decode(JSValue));
}
void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject *arg1,
void (*ArgFn2)(JSC__VM *arg0, JSC__JSGlobalObject *arg1,
JSC__JSValue JSValue2)) {
JSC::forEachInIterable(
arg1, JSC::JSValue::decode(JSValue0),
[ArgFn2](JSC::VM &vm, JSC::JSGlobalObject *global, JSC::JSValue value) -> void {
ArgFn2(&vm, global, JSC::JSValue::encode(value));
});
}
bool JSC__JSValue__isCallable(JSC__JSValue JSValue0, JSC__VM *arg1) {
return JSC::JSValue::decode(JSValue0).isCallable(reinterpret_cast<JSC::VM &>(arg1));
}
@@ -647,6 +719,9 @@ bool JSC__JSValue__isGetterSetter(JSC__JSValue JSValue0) {
bool JSC__JSValue__isHeapBigInt(JSC__JSValue JSValue0) {
return JSC::JSValue::decode(JSValue0).isHeapBigInt();
}
bool JSC__JSValue__isInt32(JSC__JSValue JSValue0) {
return JSC::JSValue::decode(JSValue0).isInt32();
}
bool JSC__JSValue__isInt32AsAnyInt(JSC__JSValue JSValue0) {
return JSC::JSValue::decode(JSValue0).isInt32AsAnyInt();
}
@@ -700,6 +775,19 @@ JSC__JSValue JSC__JSValue__jsNumberFromU16(uint16_t arg0) {
JSC__JSValue JSC__JSValue__jsNumberFromUint64(uint64_t arg0) {
return JSC::JSValue::encode(JSC::jsNumber(arg0));
};
bool JSC__JSValue__toBoolean(JSC__JSValue JSValue0) {
return JSC::JSValue::decode(JSValue0).asBoolean();
}
int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0) {
return JSC::JSValue::decode(JSValue0).asInt32();
}
JSC__JSValue JSC__JSValue__getErrorsProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject *global) {
JSC::JSObject *obj = JSC::JSValue::decode(JSValue0).getObject();
return JSC::JSValue::encode(obj->getDirect(global->vm(), global->vm().propertyNames->errors));
}
JSC__JSValue JSC__JSValue__jsTDZValue() { return JSC::JSValue::encode(JSC::jsTDZValue()); };
JSC__JSValue JSC__JSValue__jsUndefined() { return JSC::JSValue::encode(JSC::jsUndefined()); };
JSC__JSObject *JSC__JSValue__toObject(JSC__JSValue JSValue0, JSC__JSGlobalObject *arg1) {
@@ -1045,6 +1133,11 @@ void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject *ar
exceptionFromString(exception, value, arg1);
}
void JSC__Exception__getStackTrace(JSC__Exception *arg0, ZigStackTrace *trace) {
populateStackTrace(arg0->stack(), trace);
}
#pragma mark - JSC::PropertyName
bool JSC__PropertyName__eqlToIdentifier(JSC__PropertyName *arg0, const JSC__Identifier *arg1) {

View File

@@ -12,36 +12,53 @@ pub const JSObject = extern struct {
pub const name = "JSC::JSObject";
pub const namespace = "JSC";
pub extern "c" fn putAtIndex(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName, i: u32) bool;
pub fn getArrayLength(this: *JSObject) usize {
return cppFn("getArrayLength", .{
this,
});
}
pub fn getAtIndex(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName, i: u32) JSValue {
return cppFn("getAtIndex", .{
pub fn getIndex(this: *JSObject, globalThis: *JSGlobalObject, i: u32) JSValue {
return cppFn("getIndex", .{
this,
property_name,
globalThis,
i,
});
}
pub fn getDirect(this: *JSObject, globalThis: *JSGlobalObject, str: ZigString) JSValue {
return cppFn("getDirect", .{
this,
globalThis,
str,
});
}
pub fn putDirect(this: *JSObject, globalThis: *JSGlobalObject, prop: ZigString, value: JSValue) void {
return cppFn("putDirect", .{
this,
globalThis,
prop,
value,
});
}
pub const Extern = [_][]const u8{
"getArrayLength",
"getAtIndex",
"getIndex",
"putAtIndex",
"getDirect",
"putDirect",
};
};
pub const ZigString = extern struct {
ptr: [*]const u8,
len: usize,
pub const shim = Shimmer("Zig", "ZigString", @This());
pub const shim = Shimmer("", "ZigString", @This());
pub const name = "ZigString";
pub const namespace = "Zig";
pub const namespace = "";
pub fn init(slice_: []const u8) ZigString {
return ZigString{ .ptr = slice_.ptr, .len = slice_.len };
@@ -61,8 +78,13 @@ pub const ZigString = extern struct {
return C_API.JSStringCreateStatic(this.ptr, this.len);
}
pub fn toErrorInstance(this: *const ZigString, global: *JSGlobalObject) JSValue {
return shim.cppFn("toErrorInstance", .{ this, global });
}
pub const Extern = [_][]const u8{
"toValue",
"toErrorInstance",
};
};
@@ -189,24 +211,28 @@ pub const ScriptArguments = extern struct {
pub fn NewGlobalObject(comptime Type: type) type {
return struct {
const importNotImpl = "Import not implemented";
const resolveNotImpl = "resolve not implemented";
const moduleNotImpl = "Module fetch not implemented";
pub fn import(global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) ErrorableZigString {
if (comptime @hasDecl(Type, "import")) {
return @call(.{ .modifier = .always_inline }, Type.import, .{ global, specifier, source });
}
return ErrorableZigString.err(error.ImportFailed, "Import not implemented");
return ErrorableZigString.err(error.ImportFailed, ZigString.init(importNotImpl).toErrorInstance(global).asVoid());
}
pub fn resolve(global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) ErrorableZigString {
pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
if (comptime @hasDecl(Type, "resolve")) {
return @call(.{ .modifier = .always_inline }, Type.resolve, .{ global, specifier, source });
@call(.{ .modifier = .always_inline }, Type.resolve, .{ res, global, specifier, source });
return;
}
return ErrorableZigString.err(error.ResolveFailed, "resolve not implemented");
res.* = ErrorableZigString.err(error.ResolveFailed, ZigString.init(resolveNotImpl).toErrorInstance(global).asVoid());
}
pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
if (comptime @hasDecl(Type, "fetch")) {
@call(.{ .modifier = .always_inline }, Type.fetch, .{ ret, global, specifier, source });
return;
}
ret.* = ErrorableResolvedSource.err(error.FetchFailed, "Module fetch not implemented");
ret.* = ErrorableResolvedSource.err(error.FetchFailed, ZigString.init(moduleNotImpl).toErrorInstance(global).asVoid());
}
pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue {
if (comptime @hasDecl(Type, "promiseRejectionTracker")) {
@@ -721,6 +747,11 @@ pub const JSGlobalObject = extern struct {
const cppFn = shim.cppFn;
pub fn ref(this: *JSGlobalObject) C_API.JSContextRef {
return @ptrCast(C_API.JSContextRef, this);
}
pub const ctx = ref;
pub fn objectPrototype(this: *JSGlobalObject) *ObjectPrototype {
return cppFn("objectPrototype", .{this});
}
@@ -794,7 +825,7 @@ pub const JSGlobalObject = extern struct {
return cppFn("asyncGeneratorFunctionPrototype", .{this});
}
pub fn createAggregateError(globalObject: *JSGlobalObject, errors: [*]JSValue, errors_len: u16, message: ZigString) JSValue {
pub fn createAggregateError(globalObject: *JSGlobalObject, errors: [*]*c_void, errors_len: u16, message: ZigString) JSValue {
return cppFn("createAggregateError", .{ globalObject, errors, errors_len, message });
}
@@ -1070,6 +1101,13 @@ pub const JSValue = enum(i64) {
pub const name = "JSC::JSValue";
pub const namespace = "JSC";
pub inline fn cast(ptr: anytype) JSValue {
return @intToEnum(JSValue, @intCast(i64, @ptrToInt(ptr)));
}
pub fn getErrorsProperty(this: JSValue, globalObject: *JSGlobalObject) JSValue {
return cppFn("getErrorsProperty", .{ this, globalObject });
}
pub fn jsNumber(number: anytype) JSValue {
return switch (@TypeOf(number)) {
f64 => @call(.{ .modifier = .always_inline }, jsNumberFromDouble, .{number}),
@@ -1136,6 +1174,9 @@ pub const JSValue = enum(i64) {
pub fn isUInt32AsAnyInt(this: JSValue) bool {
return cppFn("isUInt32AsAnyInt", .{this});
}
pub fn isInt32(this: JSValue) bool {
return cppFn("isInt32", .{this});
}
pub fn isInt32AsAnyInt(this: JSValue) bool {
return cppFn("isInt32AsAnyInt", .{this});
}
@@ -1246,7 +1287,42 @@ pub const JSValue = enum(i64) {
});
}
pub const Extern = [_][]const u8{ "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "get", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
pub fn toBoolean(this: JSValue) bool {
return cppFn("toBoolean", .{
this,
});
}
pub fn toInt32(this: JSValue) i32 {
return cppFn("toInt32", .{
this,
});
}
pub fn isAggregateError(this: JSValue, globalObject: *JSGlobalObject) bool {
return cppFn("isAggregateError", .{ this, globalObject });
}
pub fn forEach(this: JSValue, globalObject: *JSGlobalObject, callback: fn (vm: [*c]VM, globalObject: [*c]JSGlobalObject, nextValue: JSValue) callconv(.C) void) void {
return cppFn("forEach", .{ this, globalObject, callback });
}
pub fn isIterable(this: JSValue, globalObject: *JSGlobalObject) bool {
return cppFn("isIterable", .{
this,
globalObject,
});
}
pub inline fn asRef(this: JSValue) C_API.JSValueRef {
return @intToPtr(C_API.JSValueRef, @intCast(usize, @enumToInt(this)));
}
pub inline fn asVoid(this: JSValue) *c_void {
return @intToPtr(*c_void, @intCast(usize, @enumToInt(this)));
}
pub const Extern = [_][]const u8{ "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "get", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
};
pub const PropertyName = extern struct {
@@ -1304,9 +1380,21 @@ pub const Exception = extern struct {
);
}
pub const Extern = [_][]const u8{
"create",
};
pub fn value(this: *Exception) JSValue {
return cppFn(
"value",
.{this},
);
}
pub fn getStackTrace(this: *Exception, trace: *ZigStackTrace) void {
return cppFn(
"getStackTrace",
.{ this, trace },
);
}
pub const Extern = [_][]const u8{ "create", "value", "getStackTrace" };
};
pub const JSLock = extern struct {

View File

@@ -26,7 +26,7 @@ pub const ZigGlobalObject = extern struct {
if (!sigaction_installed) {
sigaction_installed = true;
sigaction = std.mem.zeroes(std.os.Sigaction);
sigaction = std.mem.zeroes(std.os.Sigaction);
sigaction.handler = .{ .sigaction = Handler.global_signal_handler_fn };
std.os.sigaction(std.os.SIGABRT, &sigaction, null);
@@ -42,11 +42,11 @@ pub const ZigGlobalObject = extern struct {
return @call(.{ .modifier = .always_inline }, Interface.import, .{ global, specifier, source });
}
pub fn resolve(global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) ErrorableZigString {
pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.resolve, .{ global, specifier, source });
@call(.{ .modifier = .always_inline }, Interface.resolve, .{ res, global, specifier, source });
}
pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
if (comptime is_bindgen) {
@@ -107,7 +107,7 @@ pub const ZigGlobalObject = extern struct {
}
};
const ErrorCodeInt = usize;
const ErrorCodeInt = u16;
pub const ErrorCode = enum(ErrorCodeInt) {
_,
@@ -298,9 +298,10 @@ pub const ZigStackTrace = extern struct {
pub fn next(this: *SourceLineIterator) ?SourceLine {
if (this.i < 0) return null;
const source_line = this.trace.source_lines_ptr[@intCast(usize, this.i)];
const result = SourceLine{
.line = this.trace.source_lines_numbers[@intCast(usize, this.i)],
.text = this.trace.source_lines_ptr[@intCast(usize, this.i)].slice(),
.text = source_line.slice(),
};
this.i -= 1;
return result;
@@ -542,26 +543,107 @@ pub const ZigConsoleClient = struct {
) callconv(.C) void {
var console = JS.VirtualMachine.vm.console;
var i: usize = 0;
var writer = console.writer;
var buffered_writer = console.writer;
var writer = buffered_writer.writer();
if (len == 1) {
var str = vals[0].toWTFString(global);
var slice = str.slice();
var written = writer.unbuffered_writer.write(slice) catch 0;
if (written > 0 and slice[slice.len - 1] != '\n') {
_ = writer.unbuffered_writer.write("\n") catch 0;
if (Output.enable_ansi_colors) {
FormattableType.format(@TypeOf(buffered_writer.unbuffered_writer), buffered_writer.unbuffered_writer, vals[0], true) catch {};
} else {
FormattableType.format(@TypeOf(buffered_writer.unbuffered_writer), buffered_writer.unbuffered_writer, vals[0], false) catch {};
}
_ = buffered_writer.unbuffered_writer.write("\n") catch 0;
return;
}
var values = vals[0..len];
defer writer.flush() catch {};
defer buffered_writer.flush() catch {};
var last_count: usize = 0;
var tail: u8 = 0;
while (i < len) : (i += 1) {
var str = values[i].toWTFString(global);
_ = writer.write(str.slice()) catch 0;
if (Output.enable_ansi_colors) {
while (i < len) : (i += 1) {
_ = if (i > 0) (writer.write(" ") catch 0);
FormattableType.format(@TypeOf(writer), writer, values[i], true) catch {};
}
} else {
while (i < len) : (i += 1) {
_ = if (i > 0) (writer.write(" ") catch 0);
FormattableType.format(@TypeOf(writer), writer, values[i], false) catch {};
}
}
_ = writer.write("\n") catch 0;
}
const FormattableType = enum {
Error,
String,
Undefined,
Double,
Integer,
Null,
Boolean,
const CellType = CAPI.CellType;
pub fn format(comptime Writer: type, writer: Writer, value: JSValue, comptime enable_ansi_colors: bool) anyerror!void {
if (value.isCell()) {
if (CAPI.JSObjectGetPrivate(value.asRef())) |private_data_ptr| {
const priv_data = JS.JSPrivateDataPtr.from(private_data_ptr);
switch (priv_data.tag()) {
.BuildError => {
const build_error = priv_data.as(JS.BuildError);
try build_error.msg.formatWriter(Writer, writer, enable_ansi_colors);
return;
},
.ResolveError => {
const resolve_error = priv_data.as(JS.ResolveError);
try resolve_error.msg.formatWriter(Writer, writer, enable_ansi_colors);
return;
},
else => {},
}
}
switch (@intToEnum(CellType, value.asCell().getType())) {
CellType.ErrorInstanceType => {
JS.VirtualMachine.printErrorlikeObject(JS.VirtualMachine.vm, value, null, enable_ansi_colors);
return;
},
CellType.GlobalObjectType => {
_ = try writer.write("[globalThis]");
return;
},
else => {},
}
}
if (value.isInt32()) {
try writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{value.toInt32()});
} else if (value.isNumber()) {
try writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{value.asNumber()});
} else if (value.isUndefined()) {
try writer.print(comptime Output.prettyFmt("<r><d>undefined<r>", enable_ansi_colors), .{});
} else if (value.isNull()) {
try writer.print(comptime Output.prettyFmt("<r><yellow>null<r>", enable_ansi_colors), .{});
} else if (value.isBoolean()) {
if (value.toBoolean()) {
try writer.print(comptime Output.prettyFmt("<r><blue>true<r>", enable_ansi_colors), .{});
} else {
try writer.print(comptime Output.prettyFmt("<r><blue>false<r>", enable_ansi_colors), .{});
}
} else {
var str = value.toWTFString(JS.VirtualMachine.vm.global);
_ = try writer.write(str.slice());
}
}
};
pub fn count(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn countReset(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn time(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}

View File

@@ -1,4 +1,4 @@
//-- AUTOGENERATED FILE -- 1627867755
//-- AUTOGENERATED FILE -- 1627963169
// clang-format off
#pragma once

View File

@@ -21,7 +21,7 @@ typedef struct ResolvedSource {
ZigString source_code;
ZigString source_url;
uint32_t hash;
uint32_t bytecodecache_fd;
uint64_t bytecodecache_fd;
} ResolvedSource;
typedef union ErrorableResolvedSourceResult {
ResolvedSource value;

View File

@@ -49,3 +49,4 @@ pub const JSC__JSValue = bindings.JSValue;
pub const ZigString = bindings.ZigString;
pub const ZigException = bindings.ZigException;
pub const ResolvedSource = bindings.ResolvedSource;
pub const ZigStackTrace = bindings.ZigStackTrace;

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -125,8 +125,8 @@ static ZigString toZigString(JSC::Identifier *str, JSC::JSGlobalObject *global)
static WTF::StringView toStringView(ZigString str) { return WTF::StringView(str.ptr, str.len); }
static void throwException(JSC::ThrowScope &scope, ZigErrorType err, JSC::JSGlobalObject *global) {
scope.throwException(
global, JSC::Exception::create(global->vm(), JSC::JSValue((JSC::EncodedJSValue)err.ptr)));
scope.throwException(global,
JSC::Exception::create(global->vm(), JSC::JSValue((JSC::JSCell *)err.ptr)));
}
static ZigString toZigString(JSC::JSValue val, JSC::JSGlobalObject *global) {

View File

@@ -93,7 +93,11 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp
}
pub fn symbolName(comptime typeName: []const u8) []const u8 {
return comptime std.fmt.comptimePrint("{s}__{s}__{s}", .{ namespace, name, typeName });
if (comptime namespace.len > 0) {
return comptime std.fmt.comptimePrint("{s}__{s}__{s}", .{ namespace, name, typeName });
} else {
return comptime std.fmt.comptimePrint("{s}__{s}", .{ name, typeName });
}
}
pub fn exportFunctions(comptime Functions: anytype) [std.meta.fieldNames(@TypeOf(Functions)).len]StaticExport {
@@ -134,11 +138,13 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp
}
pub inline fn cppFn(comptime typeName: []const u8, args: anytype) (ret: {
@setEvalBranchQuota(99999);
if (!@hasDecl(Parent, typeName)) {
@compileError(@typeName(Parent) ++ " is missing cppFn: " ++ typeName);
}
break :ret std.meta.declarationInfo(Parent, typeName).data.Fn.return_type;
}) {
@setEvalBranchQuota(99999);
if (comptime is_bindgen) {
unreachable;
} else {