mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
[napi] Stub a couple more
This commit is contained in:
@@ -44,7 +44,7 @@ namespace WebCore {
|
||||
|
||||
const JSC::ConstructAbility s_jsZigGlobalObjectRequireCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
|
||||
const JSC::ConstructorKind s_jsZigGlobalObjectRequireCodeConstructorKind = JSC::ConstructorKind::None;
|
||||
const int s_jsZigGlobalObjectRequireCodeLength = 1224;
|
||||
const int s_jsZigGlobalObjectRequireCodeLength = 1225;
|
||||
static const JSC::Intrinsic s_jsZigGlobalObjectRequireCodeIntrinsic = JSC::NoIntrinsic;
|
||||
const char* const s_jsZigGlobalObjectRequireCode =
|
||||
"(function (name) {\n" \
|
||||
@@ -69,7 +69,7 @@ const char* const s_jsZigGlobalObjectRequireCode =
|
||||
" var fs = (globalThis[Symbol.for(\"_fs\")] ||= Bun.fs());\n" \
|
||||
" var exports = JSON.parse(fs.readFileSync(resolved, \"utf8\"));\n" \
|
||||
" requireCache.@set(resolved, exports);\n" \
|
||||
" return cached;\n" \
|
||||
" return exports;\n" \
|
||||
" } else if (resolved.endsWith(\".node\")) {\n" \
|
||||
" var module = { exports: {} };\n" \
|
||||
" globalThis.process.dlopen(module, resolved);\n" \
|
||||
|
||||
@@ -45,7 +45,7 @@ function require(name) {
|
||||
var fs = (globalThis[Symbol.for("_fs")] ||= Bun.fs());
|
||||
var exports = JSON.parse(fs.readFileSync(resolved, "utf8"));
|
||||
requireCache.@set(resolved, exports);
|
||||
return cached;
|
||||
return exports;
|
||||
} else if (resolved.endsWith(".node")) {
|
||||
var module = { exports: {} };
|
||||
globalThis.process.dlopen(module, resolved);
|
||||
|
||||
@@ -536,6 +536,10 @@ extern "C" napi_status napi_create_function(napi_env env, const char* utf8name,
|
||||
size_t length, napi_callback cb,
|
||||
void* data, napi_value* result)
|
||||
{
|
||||
if (utf8name == nullptr) {
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
|
||||
Zig::GlobalObject* globalObject = toJS(env);
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto name = WTF::String::fromUTF8(utf8name, length == NAPI_AUTO_LENGTH ? strlen(utf8name) : length).isolatedCopy();
|
||||
@@ -691,17 +695,25 @@ extern "C" napi_status napi_create_reference(napi_env env, napi_value value,
|
||||
}
|
||||
}
|
||||
|
||||
NapiPrototype* object = jsDynamicCast<NapiPrototype*>(val);
|
||||
if (!object) {
|
||||
if (NapiPrototype* object = jsDynamicCast<NapiPrototype*>(val)) {
|
||||
object->napiRef = ref;
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
|
||||
object->napiRef = ref;
|
||||
*result = toNapi(ref);
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
extern "C" napi_status napi_add_finalizer(napi_env env, napi_value js_object,
|
||||
void* native_object,
|
||||
napi_finalize finalize_cb,
|
||||
void* finalize_hint,
|
||||
napi_ref* result)
|
||||
{
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
extern "C" napi_status napi_reference_unref(napi_env env, napi_ref ref,
|
||||
uint32_t* result)
|
||||
{
|
||||
@@ -1177,6 +1189,36 @@ extern "C" napi_status napi_get_all_property_names(
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
static napi_extended_error_info last_error_info;
|
||||
|
||||
extern "C" napi_status
|
||||
napi_get_last_error_info(napi_env env, const napi_extended_error_info** result)
|
||||
{
|
||||
auto globalObject = toJS(env);
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto lastException = vm.lastException();
|
||||
if (!lastException) {
|
||||
last_error_info = {
|
||||
"",
|
||||
nullptr,
|
||||
404,
|
||||
napi_generic_failure
|
||||
};
|
||||
*result = &last_error_info;
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
last_error_info = {
|
||||
lastException->value().toWTFString(globalObject).utf8().data(),
|
||||
lastException,
|
||||
69420,
|
||||
napi_generic_failure
|
||||
};
|
||||
*result = &last_error_info;
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
extern "C" napi_status napi_define_class(napi_env env,
|
||||
const char* utf8name,
|
||||
size_t length,
|
||||
@@ -1186,6 +1228,10 @@ extern "C" napi_status napi_define_class(napi_env env,
|
||||
const napi_property_descriptor* properties,
|
||||
napi_value* result)
|
||||
{
|
||||
if (utf8name == nullptr) {
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
|
||||
Zig::GlobalObject* globalObject = toJS(env);
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
size_t len = length;
|
||||
|
||||
Reference in New Issue
Block a user