mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[napi] Implement napi_get_property_names
This commit is contained in:
@@ -1289,5 +1289,32 @@ extern "C" napi_status napi_coerce_to_string(napi_env env, napi_value value,
|
||||
return napi_generic_failure;
|
||||
}
|
||||
scope.clearException();
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
extern "C" napi_status napi_get_property_names(napi_env env, napi_value object,
|
||||
napi_value* result)
|
||||
{
|
||||
|
||||
Zig::GlobalObject* globalObject = toJS(env);
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
|
||||
JSC::JSValue jsValue = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(object));
|
||||
if (!jsValue || !jsValue.isObject()) {
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
|
||||
auto scope = DECLARE_CATCH_SCOPE(vm);
|
||||
JSC::EnsureStillAliveScope ensureStillAlive(jsValue);
|
||||
JSC::JSValue value = JSC::ownPropertyKeys(globalObject, jsValue.getObject(), PropertyNameMode::Strings, DontEnumPropertiesMode::Include, std::nullopt);
|
||||
if (UNLIKELY(scope.exception())) {
|
||||
*result = reinterpret_cast<napi_value>(JSC::JSValue::encode(JSC::jsUndefined()));
|
||||
return napi_generic_failure;
|
||||
}
|
||||
scope.clearException();
|
||||
JSC::EnsureStillAliveScope ensureStillAlive1(value);
|
||||
|
||||
*result = toNapi(value);
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
@@ -65,6 +65,7 @@
|
||||
_napi_get_node_version;
|
||||
_napi_get_null;
|
||||
_napi_get_property;
|
||||
_napi_get_property_names;
|
||||
_napi_get_prototype;
|
||||
_napi_get_reference_value;
|
||||
_napi_get_threadsafe_function_context;
|
||||
|
||||
@@ -64,6 +64,7 @@ _napi_get_new_target
|
||||
_napi_get_node_version
|
||||
_napi_get_null
|
||||
_napi_get_property
|
||||
_napi_get_property_names
|
||||
_napi_get_prototype
|
||||
_napi_get_reference_value
|
||||
_napi_get_threadsafe_function_context
|
||||
@@ -122,4 +123,4 @@ _napi_throw_type_error
|
||||
_napi_typeof
|
||||
_napi_unref_threadsafe_function
|
||||
_napi_unwrap
|
||||
_napi_wrap
|
||||
_napi_wrap
|
||||
Reference in New Issue
Block a user