|
14 | 14 | #include <algorithm>
|
15 | 15 | #include <cassert>
|
16 | 16 | #include <cmath>
|
17 |
| -#include <cstdarg> |
18 | 17 | #include <vector>
|
19 | 18 | #include "uv.h"
|
20 | 19 | #include "node_api.h"
|
@@ -1008,6 +1007,28 @@ napi_status napi_get_property(napi_env env,
|
1008 | 1007 | return GET_RETURN_STATUS(env);
|
1009 | 1008 | }
|
1010 | 1009 |
|
| 1010 | +napi_status napi_delete_property(napi_env env, |
| 1011 | + napi_value object, |
| 1012 | + napi_value key, |
| 1013 | + bool* result) { |
| 1014 | + NAPI_PREAMBLE(env); |
| 1015 | + CHECK_ARG(env, key); |
| 1016 | + |
| 1017 | + v8::Isolate* isolate = env->isolate; |
| 1018 | + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 1019 | + v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key); |
| 1020 | + v8::Local<v8::Object> obj; |
| 1021 | + |
| 1022 | + CHECK_TO_OBJECT(env, context, obj, object); |
| 1023 | + v8::Maybe<bool> delete_maybe = obj->Delete(context, k); |
| 1024 | + CHECK_MAYBE_NOTHING(env, delete_maybe, napi_generic_failure); |
| 1025 | + |
| 1026 | + if (result != NULL) |
| 1027 | + *result = delete_maybe.FromMaybe(false); |
| 1028 | + |
| 1029 | + return GET_RETURN_STATUS(env); |
| 1030 | +} |
| 1031 | + |
1011 | 1032 | napi_status napi_set_named_property(napi_env env,
|
1012 | 1033 | napi_value object,
|
1013 | 1034 | const char* utf8name,
|
@@ -1145,6 +1166,26 @@ napi_status napi_get_element(napi_env env,
|
1145 | 1166 | return GET_RETURN_STATUS(env);
|
1146 | 1167 | }
|
1147 | 1168 |
|
| 1169 | +napi_status napi_delete_element(napi_env env, |
| 1170 | + napi_value object, |
| 1171 | + uint32_t index, |
| 1172 | + bool* result) { |
| 1173 | + NAPI_PREAMBLE(env); |
| 1174 | + |
| 1175 | + v8::Isolate* isolate = env->isolate; |
| 1176 | + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 1177 | + v8::Local<v8::Object> obj; |
| 1178 | + |
| 1179 | + CHECK_TO_OBJECT(env, context, obj, object); |
| 1180 | + v8::Maybe<bool> delete_maybe = obj->Delete(context, index); |
| 1181 | + CHECK_MAYBE_NOTHING(env, delete_maybe, napi_generic_failure); |
| 1182 | + |
| 1183 | + if (result != NULL) |
| 1184 | + *result = delete_maybe.FromMaybe(false); |
| 1185 | + |
| 1186 | + return GET_RETURN_STATUS(env); |
| 1187 | +} |
| 1188 | + |
1148 | 1189 | napi_status napi_define_properties(napi_env env,
|
1149 | 1190 | napi_value object,
|
1150 | 1191 | size_t property_count,
|
@@ -1973,16 +2014,16 @@ napi_status napi_wrap(napi_env env,
|
1973 | 2014 |
|
1974 | 2015 | // Create a wrapper object with an internal field to hold the wrapped pointer.
|
1975 | 2016 | v8::Local<v8::ObjectTemplate> wrapperTemplate =
|
1976 |
| - v8::ObjectTemplate::New(isolate); |
| 2017 | + v8::ObjectTemplate::New(isolate); |
1977 | 2018 | wrapperTemplate->SetInternalFieldCount(1);
|
1978 | 2019 | v8::Local<v8::Object> wrapper =
|
1979 |
| - wrapperTemplate->NewInstance(context).ToLocalChecked(); |
| 2020 | + wrapperTemplate->NewInstance(context).ToLocalChecked(); |
1980 | 2021 | wrapper->SetInternalField(0, v8::External::New(isolate, native_object));
|
1981 | 2022 |
|
1982 | 2023 | // Insert the wrapper into the object's prototype chain.
|
1983 | 2024 | v8::Local<v8::Value> proto = obj->GetPrototype();
|
1984 |
| - wrapper->SetPrototype(proto); |
1985 |
| - obj->SetPrototype(wrapper); |
| 2025 | + CHECK(wrapper->SetPrototype(context, proto).FromJust()); |
| 2026 | + CHECK(obj->SetPrototype(context, wrapper).FromJust()); |
1986 | 2027 |
|
1987 | 2028 | if (result != nullptr) {
|
1988 | 2029 | // The returned reference should be deleted via napi_delete_reference()
|
@@ -2287,7 +2328,7 @@ napi_status napi_instanceof(napi_env env,
|
2287 | 2328 | }
|
2288 | 2329 |
|
2289 | 2330 | if (env->has_instance_available) {
|
2290 |
| - napi_value value, js_result, has_instance = nullptr; |
| 2331 | + napi_value value, js_result = nullptr, has_instance = nullptr; |
2291 | 2332 | napi_status status = napi_generic_failure;
|
2292 | 2333 | napi_valuetype value_type;
|
2293 | 2334 |
|
|
0 commit comments