温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/util/types/isExternal
点击访问原文链接

Node util/types.isExternal function | API Reference | Bun

Node util/types.isExternal function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:util/types/isExternalFisExternal

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:util/types/isExternalFisExternal

function

util.types.isExternal #include napi_value result; static napi_value MyNapi(napi_env env, napi_callback_info info) { int* raw = (int*) malloc(1024); napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result); if (status != napi_ok) { napi_throw_error(env, NULL, "napi_create_external failed"); return NULL; } return result; } ... DECLARE_NAPI_PROPERTY("myNapi", MyNapi) ... ``` ```js import native from 'napi_addon.node'; import { types } from 'node:util'; const data = native.myNapi(); types.isExternal(data); // returns true types.isExternal(0); // returns false types.isExternal(new String('foo')); // returns false ``` For further information on `napi_create_external`, refer to [`napi_create_external()`](https://nodejs.org/docs/latest-v25.x/api/n-api.html#napi_create_external)." data-algolia-static="false" data-algolia-merged="false" data-type="Function">function isExternal(object: unknown): boolean;

Returns true if the value is a native External value.

A native External value is a special type of object that contains a raw C++ pointer (void*) for access from native code, and has no other properties. Such objects are created either by Node.js internals or native addons. In JavaScript, they are frozen objects with a null prototype.

#include js_native_api.h>
#include stdlib.h>
napi_value result;
static napi_value MyNapi(napi_env env, napi_callback_info info) {
int* raw = (int*) malloc(1024);
napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);
if (status != napi_ok) {
napi_throw_error(env, NULL, "napi_create_external failed");
return NULL;
}
return result;
}
...
DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
...
import native from 'napi_addon.node';
import { types } from 'node:util';

const data = native.myNapi();
types.isExternal(data); // returns true
types.isExternal(0); // returns false
types.isExternal(new String('foo')); // returns false

For further information on napi_create_external, refer to napi_create_external().

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node util/types.isExternal function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:util/types.isExternal | Bun