mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
f60720090c
Moving some additional NAPI and. FFI tests out of the tree root.
39 lines
973 B
Rust
39 lines
973 B
Rust
// Copyright 2018-2024 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()
|
|
));
|
|
}
|