[napi] Implement napi_get_property_names

This commit is contained in:
Jarred Sumner
2022-07-12 02:32:23 -07:00
parent a63a0ccc10
commit 83ad9fa780
3 changed files with 30 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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