2018-11-17 12:34:54 -08:00
|
|
|
#include <js_native_api.h>
|
2017-03-24 01:26:09 -07:00
|
|
|
#include "../common.h"
|
2023-09-06 21:11:09 +08:00
|
|
|
#include "../entry_point.h"
|
2017-03-20 14:55:26 -07:00
|
|
|
|
2018-04-23 22:20:47 -04:00
|
|
|
static napi_value New(napi_env env, napi_callback_info info) {
|
2017-03-24 01:26:09 -07:00
|
|
|
size_t argc = 1;
|
|
|
|
napi_value args[1];
|
2021-02-03 12:01:28 -08:00
|
|
|
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
|
2017-03-20 14:55:26 -07:00
|
|
|
|
2017-03-24 01:26:09 -07:00
|
|
|
napi_value description = NULL;
|
2017-03-20 14:55:26 -07:00
|
|
|
if (argc >= 1) {
|
|
|
|
napi_valuetype valuetype;
|
2021-02-03 12:01:28 -08:00
|
|
|
NODE_API_CALL(env, napi_typeof(env, args[0], &valuetype));
|
2017-03-24 01:26:09 -07:00
|
|
|
|
2021-02-03 12:01:28 -08:00
|
|
|
NODE_API_ASSERT(env, valuetype == napi_string,
|
2017-08-30 02:48:41 -07:00
|
|
|
"Wrong type of arguments. Expects a string.");
|
2017-03-24 01:26:09 -07:00
|
|
|
|
|
|
|
description = args[0];
|
2017-03-20 14:55:26 -07:00
|
|
|
}
|
|
|
|
|
2017-03-24 01:26:09 -07:00
|
|
|
napi_value symbol;
|
2021-02-03 12:01:28 -08:00
|
|
|
NODE_API_CALL(env, napi_create_symbol(env, description, &symbol));
|
2017-03-20 14:55:26 -07:00
|
|
|
|
2017-03-24 01:26:09 -07:00
|
|
|
return symbol;
|
|
|
|
}
|
2017-03-20 14:55:26 -07:00
|
|
|
|
2018-11-17 12:34:54 -08:00
|
|
|
EXTERN_C_START
|
|
|
|
napi_value Init(napi_env env, napi_value exports) {
|
2017-03-20 14:55:26 -07:00
|
|
|
napi_property_descriptor properties[] = {
|
2021-02-03 12:01:28 -08:00
|
|
|
DECLARE_NODE_API_PROPERTY("New", New),
|
2017-03-20 14:55:26 -07:00
|
|
|
};
|
|
|
|
|
2021-02-03 12:01:28 -08:00
|
|
|
NODE_API_CALL(env, napi_define_properties(
|
2017-08-30 02:48:41 -07:00
|
|
|
env, exports, sizeof(properties) / sizeof(*properties), properties));
|
|
|
|
|
|
|
|
return exports;
|
2017-03-20 14:55:26 -07:00
|
|
|
}
|
2018-11-17 12:34:54 -08:00
|
|
|
EXTERN_C_END
|