diff options
author | Shelley Vohr <shelley.vohr@gmail.com> | 2020-09-25 22:11:13 -0700 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-10-07 08:31:43 -0700 |
commit | 19f14517c7637b0e277b4fc3fdfe4473e5cc1262 (patch) | |
tree | 491c0bb12fc386b26b2a3e5b85c0d55ab32a7f27 /src/js_native_api_v8.cc | |
parent | c208a20f9c4bdf4d8dc57d14629dd296b8681327 (diff) | |
download | node-new-19f14517c7637b0e277b4fc3fdfe4473e5cc1262.tar.gz |
n-api: support for object freeze/seal
PR-URL: https://github.com/nodejs/node/pull/35359
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'src/js_native_api_v8.cc')
-rw-r--r-- | src/js_native_api_v8.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 0a069b3ae4..1feabfd879 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -1362,6 +1362,42 @@ napi_status napi_define_properties(napi_env env, return GET_RETURN_STATUS(env); } +napi_status napi_object_freeze(napi_env env, + napi_value object) { + NAPI_PREAMBLE(env); + + v8::Local<v8::Context> context = env->context(); + v8::Local<v8::Object> obj; + + CHECK_TO_OBJECT(env, context, obj, object); + + v8::Maybe<bool> set_frozen = + obj->SetIntegrityLevel(context, v8::IntegrityLevel::kFrozen); + + RETURN_STATUS_IF_FALSE_WITH_PREAMBLE(env, + set_frozen.FromMaybe(false), napi_generic_failure); + + return GET_RETURN_STATUS(env); +} + +napi_status napi_object_seal(napi_env env, + napi_value object) { + NAPI_PREAMBLE(env); + + v8::Local<v8::Context> context = env->context(); + v8::Local<v8::Object> obj; + + CHECK_TO_OBJECT(env, context, obj, object); + + v8::Maybe<bool> set_sealed = + obj->SetIntegrityLevel(context, v8::IntegrityLevel::kSealed); + + RETURN_STATUS_IF_FALSE_WITH_PREAMBLE(env, + set_sealed.FromMaybe(false), napi_generic_failure); + + return GET_RETURN_STATUS(env); +} + napi_status napi_is_array(napi_env env, napi_value value, bool* result) { CHECK_ENV(env); CHECK_ARG(env, value); |