emnapi 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/library_napi.js +52 -0
- package/include/node/emnapi.h +1 -1
- package/include/node/js_native_api.h +11 -0
- package/package.json +1 -1
package/dist/library_napi.js
CHANGED
|
@@ -3071,6 +3071,55 @@ function _napi_create_object(env, result) {
|
|
|
3071
3071
|
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3072
3072
|
return envObject.clearLastError();
|
|
3073
3073
|
}
|
|
3074
|
+
/**
|
|
3075
|
+
* @__sig ipppppp
|
|
3076
|
+
*/
|
|
3077
|
+
function _napi_create_object_with_properties(env, prototype_or_null, property_names, property_values, property_count, result) {
|
|
3078
|
+
if (!env)
|
|
3079
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
3080
|
+
// @ts-expect-error
|
|
3081
|
+
var envObject = emnapiCtx.envStore.get(env);
|
|
3082
|
+
envObject.checkGCAccess();
|
|
3083
|
+
if (!result)
|
|
3084
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3085
|
+
{{{ from64('property_count') }}};
|
|
3086
|
+
property_count = property_count >>> 0;
|
|
3087
|
+
if (property_count > 0) {
|
|
3088
|
+
if (!property_names)
|
|
3089
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3090
|
+
if (!property_values)
|
|
3091
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
3092
|
+
}
|
|
3093
|
+
var v8_prototype_or_null = prototype_or_null
|
|
3094
|
+
? emnapiCtx.handleStore.get(prototype_or_null).value
|
|
3095
|
+
: null;
|
|
3096
|
+
var properties = {};
|
|
3097
|
+
{{{ from64('property_names') }}};
|
|
3098
|
+
{{{ from64('property_values') }}};
|
|
3099
|
+
for (var i = 0; i < property_count; i++) {
|
|
3100
|
+
var name_value = emnapiCtx.handleStore.get({{{ makeGetValue('property_names', 'i * ' + POINTER_SIZE, '*') }}}).value;
|
|
3101
|
+
if (!(typeof name_value === "string" || typeof name_value === "symbol"))
|
|
3102
|
+
return envObject.setLastError(4 /* napi_status.napi_name_expected */);
|
|
3103
|
+
properties[name_value] = {
|
|
3104
|
+
value: emnapiCtx.handleStore.get({{{ makeGetValue('property_values', 'i * ' + POINTER_SIZE, '*') }}}).value,
|
|
3105
|
+
writable: true,
|
|
3106
|
+
enumerable: true,
|
|
3107
|
+
configurable: true
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
var obj;
|
|
3111
|
+
try {
|
|
3112
|
+
obj = Object.defineProperties(Object.create(v8_prototype_or_null), properties);
|
|
3113
|
+
}
|
|
3114
|
+
catch (_) {
|
|
3115
|
+
return envObject.setLastError(9 /* napi_status.napi_generic_failure */);
|
|
3116
|
+
}
|
|
3117
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3118
|
+
var value = emnapiCtx.addToCurrentScope(obj).id;
|
|
3119
|
+
{{{ from64('result') }}};
|
|
3120
|
+
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
3121
|
+
return envObject.clearLastError();
|
|
3122
|
+
}
|
|
3074
3123
|
/**
|
|
3075
3124
|
* @__sig ippp
|
|
3076
3125
|
*/
|
|
@@ -6955,6 +7004,9 @@ function _napi_get_version(env, result) {
|
|
|
6955
7004
|
napi_create_object: _napi_create_object,
|
|
6956
7005
|
napi_create_object__deps: ["$emnapiCtx"],
|
|
6957
7006
|
napi_create_object__sig: "ipp",
|
|
7007
|
+
napi_create_object_with_properties: _napi_create_object_with_properties,
|
|
7008
|
+
napi_create_object_with_properties__deps: ["$emnapiCtx"],
|
|
7009
|
+
napi_create_object_with_properties__sig: "ipppppp",
|
|
6958
7010
|
napi_create_promise: _napi_create_promise,
|
|
6959
7011
|
napi_create_promise__deps: ["$emnapiCtx"],
|
|
6960
7012
|
napi_create_promise__sig: "ippp",
|
package/include/node/emnapi.h
CHANGED
|
@@ -72,6 +72,17 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_boolean(napi_env env,
|
|
|
72
72
|
// Methods to create Primitive types/Objects
|
|
73
73
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_object(napi_env env,
|
|
74
74
|
napi_value* result);
|
|
75
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
76
|
+
#define NODE_API_EXPERIMENTAL_HAS_CREATE_OBJECT_WITH_PROPERTIES
|
|
77
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
78
|
+
napi_create_object_with_properties(napi_env env,
|
|
79
|
+
napi_value prototype_or_null,
|
|
80
|
+
napi_value* property_names,
|
|
81
|
+
napi_value* property_values,
|
|
82
|
+
size_t property_count,
|
|
83
|
+
napi_value* result);
|
|
84
|
+
#endif // NAPI_EXPERIMENTAL
|
|
85
|
+
|
|
75
86
|
NAPI_EXTERN napi_status NAPI_CDECL napi_create_array(napi_env env,
|
|
76
87
|
napi_value* result);
|
|
77
88
|
NAPI_EXTERN napi_status NAPI_CDECL
|