diff options
author | 2022-07-12 02:32:23 -0700 | |
---|---|---|
committer | 2022-07-12 02:50:47 -0700 | |
commit | 83ad9fa780295a272a7ca789f8a44cd58600a522 (patch) | |
tree | 8bd10f457d0957583337272aa6ead44233532818 | |
parent | a63a0ccc105039278faaf920940ffa737e9b98df (diff) | |
download | bun-83ad9fa780295a272a7ca789f8a44cd58600a522.tar.gz bun-83ad9fa780295a272a7ca789f8a44cd58600a522.tar.zst bun-83ad9fa780295a272a7ca789f8a44cd58600a522.zip |
[napi] Implement `napi_get_property_names`
-rw-r--r-- | src/bun.js/bindings/napi.cpp | 27 | ||||
-rw-r--r-- | src/symbols.dyn | 1 | ||||
-rw-r--r-- | src/symbols.txt | 3 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index 295a1e02b..5ed1ef142 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -1290,4 +1290,31 @@ extern "C" napi_status napi_coerce_to_string(napi_env env, napi_value value, } 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; }
\ No newline at end of file diff --git a/src/symbols.dyn b/src/symbols.dyn index 7957ef59a..0e02635bc 100644 --- a/src/symbols.dyn +++ b/src/symbols.dyn @@ -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; diff --git a/src/symbols.txt b/src/symbols.txt index 3ac1fa843..a250f77ea 100644 --- a/src/symbols.txt +++ b/src/symbols.txt @@ -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
\ No newline at end of file |