1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 01:59:06 -05:00
denoland-deno/test_napi/src/symbol.rs
2023-05-21 13:14:48 -06:00

39 lines
973 B
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::assert_napi_ok;
use crate::napi_get_callback_info;
use crate::napi_new_property;
use napi_sys::ValueType::napi_string;
use napi_sys::*;
extern "C" fn symbol_new(
env: napi_env,
info: napi_callback_info,
) -> napi_value {
let (args, argc, _) = napi_get_callback_info!(env, info, 1);
let mut description: napi_value = std::ptr::null_mut();
if argc >= 1 {
let mut ty = -1;
assert_napi_ok!(napi_typeof(env, args[0], &mut ty));
assert_eq!(ty, napi_string);
description = args[0];
}
let mut symbol: napi_value = std::ptr::null_mut();
assert_napi_ok!(napi_create_symbol(env, description, &mut symbol));
symbol
}
pub fn init(env: napi_env, exports: napi_value) {
let properties = &[napi_new_property!(env, "symbolNew", symbol_new)];
assert_napi_ok!(napi_define_properties(
env,
exports,
properties.len(),
properties.as_ptr()
));
}