@contrast/agent-bundle 5.42.0 → 5.45.1
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/README.md +1 -10
- package/node_modules/@contrast/agent/README.md +1 -10
- package/node_modules/@contrast/agent/package.json +12 -12
- package/node_modules/@contrast/agent-swc-plugin/package.json +3 -3
- package/node_modules/@contrast/agentify/lib/rewrite-hooks.js +3 -3
- package/node_modules/@contrast/agentify/lib/utils.js +13 -7
- package/node_modules/@contrast/agentify/package.json +17 -17
- package/node_modules/@contrast/architecture-components/package.json +6 -6
- package/node_modules/@contrast/assess/lib/dataflow/propagation/install/ejs/template.js +1 -1
- package/node_modules/@contrast/assess/lib/dataflow/propagation/install/pug/index.js +1 -1
- package/node_modules/@contrast/assess/lib/dataflow/sinks/install/http/server-response.js +1 -12
- package/node_modules/@contrast/assess/lib/dataflow/sinks/install/restify.js +1 -1
- package/node_modules/@contrast/assess/lib/dataflow/sources/install/http.js +1 -1
- package/node_modules/@contrast/assess/lib/dataflow/tracker.js +1 -1
- package/node_modules/@contrast/assess/lib/get-source-context.js +1 -1
- package/node_modules/@contrast/assess/lib/response-scanning/install/http.js +0 -12
- package/node_modules/@contrast/assess/package.json +14 -14
- package/node_modules/@contrast/code-events/binding.gyp +1 -1
- package/node_modules/@contrast/code-events/package.json +11 -9
- package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi108.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi115.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi127.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/{@contrast+code-events.abi93.node → @contrast+code-events.abi137.node} +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi108.armv8.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi115.armv8.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi127.armv8.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi137.armv8.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi108.glibc.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi108.musl.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi115.glibc.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi115.musl.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi127.glibc.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi127.musl.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi137.glibc.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi137.musl.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi108.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi115.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi127.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi137.node +0 -0
- package/node_modules/@contrast/common/lib/constants.d.ts +1 -1
- package/node_modules/@contrast/common/lib/constants.js +1 -1
- package/node_modules/@contrast/common/lib/index.js +15 -15
- package/node_modules/@contrast/common/lib/primordials.d.ts +22 -20
- package/node_modules/@contrast/common/lib/types.d.ts +18 -6
- package/node_modules/@contrast/common/package.json +2 -2
- package/node_modules/@contrast/config/lib/options.js +29 -4
- package/node_modules/@contrast/config/package.json +4 -4
- package/node_modules/@contrast/core/lib/app-info.js +53 -74
- package/node_modules/@contrast/core/lib/index.d.ts +17 -1
- package/node_modules/@contrast/core/lib/sensitive-data-masking/index.js +33 -5
- package/node_modules/@contrast/core/package.json +10 -9
- package/node_modules/@contrast/deadzones/package.json +6 -6
- package/node_modules/@contrast/dep-hooks/lib/export-handler-registry.d.ts +17 -13
- package/node_modules/@contrast/dep-hooks/lib/export-handler-registry.js +16 -4
- package/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.d.ts +2 -2
- package/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.js +2 -3
- package/node_modules/@contrast/dep-hooks/lib/handler-invoker.d.ts +6 -6
- package/node_modules/@contrast/dep-hooks/lib/handler-invoker.js +0 -1
- package/node_modules/@contrast/dep-hooks/lib/helpers.d.ts +0 -7
- package/node_modules/@contrast/dep-hooks/lib/helpers.js +2 -18
- package/node_modules/@contrast/dep-hooks/lib/index.d.ts +17 -12
- package/node_modules/@contrast/dep-hooks/lib/index.js +5 -3
- package/node_modules/@contrast/dep-hooks/lib/package-finder.d.ts +2 -1
- package/node_modules/@contrast/dep-hooks/lib/package-finder.js +6 -6
- package/node_modules/@contrast/dep-hooks/package.json +4 -3
- package/node_modules/@contrast/distringuish/package.json +7 -6
- package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi108.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi115.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi127.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/{@contrast+distringuish.abi93.node → @contrast+distringuish.abi137.node} +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi108.armv8.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi115.armv8.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi127.armv8.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi137.armv8.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi108.glibc.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi108.musl.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi115.glibc.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi115.musl.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi127.glibc.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi127.musl.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi137.glibc.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi137.musl.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi108.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi115.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi127.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi137.node +0 -0
- package/node_modules/@contrast/esm-hooks/lib/debug-methods.mjs +4 -4
- package/node_modules/@contrast/esm-hooks/lib/get-file-type.mjs +2 -9
- package/node_modules/@contrast/esm-hooks/lib/hooks.mjs +0 -2
- package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/fs/promises.mjs +2 -0
- package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/fs.mjs +3 -0
- package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/util.mjs +1 -0
- package/node_modules/@contrast/esm-hooks/package.json +7 -7
- package/node_modules/@contrast/fn-inspect/package.json +9 -5
- package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi108.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi115.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi127.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/{@contrast+fn-inspect.abi93.node → @contrast+fn-inspect.abi137.node} +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi108.armv8.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi115.armv8.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi127.armv8.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi137.armv8.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi108.glibc.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi108.musl.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi115.glibc.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi115.musl.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi127.glibc.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi127.musl.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi137.glibc.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/{@contrast+fn-inspect.abi93.musl.node → @contrast+fn-inspect.abi137.musl.node} +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi108.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi115.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi127.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi137.node +0 -0
- package/node_modules/@contrast/instrumentation/lib/http2.js +0 -11
- package/node_modules/@contrast/instrumentation/package.json +6 -6
- package/node_modules/@contrast/library-analysis/lib/install/library-reporting/dep.json +312 -224
- package/node_modules/@contrast/library-analysis/package.json +6 -6
- package/node_modules/@contrast/logger/lib/index.js +18 -8
- package/node_modules/@contrast/logger/lib/serializers.js +5 -5
- package/node_modules/@contrast/logger/lib/utils.d.ts +0 -6
- package/node_modules/@contrast/logger/package.json +4 -4
- package/node_modules/@contrast/metrics/lib/index.d.ts +6 -6
- package/node_modules/@contrast/metrics/lib/index.js +0 -1
- package/node_modules/@contrast/metrics/package.json +7 -7
- package/node_modules/@contrast/patcher/package.json +3 -3
- package/node_modules/@contrast/perf/package.json +7 -4
- package/node_modules/@contrast/protect/lib/hardening/handlers.js +37 -21
- package/node_modules/@contrast/protect/lib/index.d.ts +3 -2
- package/node_modules/@contrast/protect/lib/index.js +9 -2
- package/node_modules/@contrast/protect/lib/input-analysis/handlers.js +275 -233
- package/node_modules/@contrast/protect/lib/input-analysis/install/http.js +3 -4
- package/node_modules/@contrast/protect/lib/input-tracing/{handlers/index.js → handlers.js} +15 -15
- package/node_modules/@contrast/protect/lib/input-tracing/index.js +0 -1
- package/node_modules/@contrast/protect/lib/make-source-context.js +5 -7
- package/node_modules/@contrast/protect/lib/policy.js +130 -95
- package/node_modules/@contrast/protect/lib/semantic-analysis/handlers.js +19 -18
- package/node_modules/@contrast/protect/package.json +12 -12
- package/node_modules/@contrast/reporter/lib/index.js +1 -1
- package/node_modules/@contrast/reporter/lib/reporters/base.d.ts +0 -1
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.d.ts +4 -2
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.js +14 -14
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.d.ts +43 -6
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.js +262 -429
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/server-inventory.d.ts +3 -3
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/index.js +17 -7
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.js +12 -13
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/utils.js +6 -7
- package/node_modules/@contrast/reporter/lib/reporters/file.js +1 -1
- package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.d.ts +2 -3
- package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.js +72 -86
- package/node_modules/@contrast/reporter/lib/reporters/security-logger/messages.js +6 -7
- package/node_modules/@contrast/reporter/lib/validators.js +0 -1
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/.husky/pre-commit +2 -2
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/.taprc +5 -0
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/README.md +2 -4
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/bench.js +5 -36
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/index.js +56 -300
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/package.json +12 -7
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test.js +1684 -0
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/types/index.d.ts +1 -2
- package/node_modules/@contrast/reporter/package.json +10 -10
- package/node_modules/@contrast/rewriter/lib/index.js +5 -43
- package/node_modules/@contrast/rewriter/package.json +8 -8
- package/node_modules/@contrast/route-coverage/lib/install/express/express5.js +0 -5
- package/node_modules/@contrast/route-coverage/lib/install/restify.js +1 -1
- package/node_modules/@contrast/route-coverage/package.json +10 -10
- package/node_modules/@contrast/scopes/package.json +6 -6
- package/node_modules/@contrast/sec-obs/lib/traces/http.js +1 -1
- package/node_modules/@contrast/sec-obs/lib/traces/http.test.js +1 -1
- package/node_modules/@contrast/sec-obs/package.json +10 -10
- package/node_modules/@contrast/sources/lib/index.js +1 -1
- package/node_modules/@contrast/sources/lib/index.test.js +0 -26
- package/node_modules/@contrast/sources/package.json +3 -3
- package/node_modules/@contrast/telemetry/package.json +6 -6
- package/node_modules/@opentelemetry/semantic-conventions/README.md +3 -2
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.d.ts +4350 -2882
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js +4350 -2882
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.d.ts +136 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.js +154 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.d.ts +713 -141
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js +713 -141
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.d.ts +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.js +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.d.ts +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.d.ts +7 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js +7 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.d.ts +5 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.js +23 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.d.ts +4350 -2882
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js +4350 -2882
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.d.ts +136 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.js +154 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.d.ts +713 -141
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js +713 -141
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.d.ts +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.js +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.d.ts +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.js +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.d.ts +7 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js +7 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.d.ts +5 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.js +23 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.d.ts +4350 -2882
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js +4354 -2883
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.d.ts +136 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.js +157 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.d.ts +713 -141
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js +720 -147
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.d.ts +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js +2 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index.d.ts +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index.js +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/index.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.d.ts +7 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js +10 -4
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.d.ts +5 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.js +26 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.js.map +1 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/package.json +6 -7
- package/node_modules/@swc/core/README.md +5 -0
- package/node_modules/@swc/core/binding.d.ts +2 -2
- package/node_modules/@swc/core/index.d.ts +5 -4
- package/node_modules/@swc/core/index.js +2 -2
- package/node_modules/@swc/core/package.json +12 -12
- package/node_modules/@swc/core-darwin-arm64/package.json +1 -1
- package/node_modules/@swc/core-darwin-arm64/swc.darwin-arm64.node +0 -0
- package/node_modules/@swc/core-darwin-x64/package.json +1 -1
- package/node_modules/@swc/core-darwin-x64/swc.darwin-x64.node +0 -0
- package/node_modules/@swc/core-linux-arm64-gnu/package.json +1 -1
- package/node_modules/@swc/core-linux-arm64-gnu/swc.linux-arm64-gnu.node +0 -0
- package/node_modules/@swc/core-linux-arm64-musl/package.json +1 -1
- package/node_modules/@swc/core-linux-arm64-musl/swc.linux-arm64-musl.node +0 -0
- package/node_modules/@swc/core-linux-x64-gnu/package.json +1 -1
- package/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node +0 -0
- package/node_modules/@swc/core-linux-x64-musl/package.json +1 -1
- package/node_modules/@swc/core-linux-x64-musl/swc.linux-x64-musl.node +0 -0
- package/node_modules/@swc/core-win32-arm64-msvc/package.json +1 -1
- package/node_modules/@swc/core-win32-arm64-msvc/swc.win32-arm64-msvc.node +0 -0
- package/node_modules/@swc/core-win32-x64-msvc/package.json +1 -1
- package/node_modules/@swc/core-win32-x64-msvc/swc.win32-x64-msvc.node +0 -0
- package/node_modules/@swc/types/index.d.ts +14 -5
- package/node_modules/@swc/types/package.json +2 -2
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/buffer.d.ts +1 -1
- package/node_modules/@types/node/child_process.d.ts +26 -122
- package/node_modules/@types/node/crypto.d.ts +44 -10
- package/node_modules/@types/node/dns.d.ts +5 -0
- package/node_modules/@types/node/fs/promises.d.ts +41 -26
- package/node_modules/@types/node/fs.d.ts +52 -35
- package/node_modules/@types/node/globals.d.ts +148 -347
- package/node_modules/@types/node/http.d.ts +29 -5
- package/node_modules/@types/node/https.d.ts +5 -0
- package/node_modules/@types/node/index.d.ts +7 -2
- package/node_modules/@types/node/inspector.d.ts +187 -4089
- package/node_modules/@types/node/inspector.generated.d.ts +4052 -0
- package/node_modules/@types/node/module.d.ts +1 -0
- package/node_modules/@types/node/net.d.ts +21 -0
- package/node_modules/@types/node/package.json +3 -3
- package/node_modules/@types/node/sqlite.d.ts +34 -0
- package/node_modules/@types/node/test.d.ts +104 -0
- package/node_modules/@types/node/tls.d.ts +32 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +7 -2
- package/node_modules/@types/node/ts5.7/index.d.ts +7 -2
- package/node_modules/@types/node/url.d.ts +19 -5
- package/node_modules/@types/node/util.d.ts +6 -4
- package/node_modules/@types/node/vm.d.ts +73 -10
- package/node_modules/@types/node/wasi.d.ts +21 -0
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/{dom-events.d.ts → web-globals/events.d.ts} +47 -52
- package/node_modules/@types/node/web-globals/fetch.d.ts +50 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/worker_threads.d.ts +51 -3
- package/node_modules/axios/CHANGELOG.md +58 -0
- package/node_modules/axios/README.md +87 -10
- package/node_modules/axios/dist/axios.js +355 -289
- package/node_modules/axios/dist/axios.js.map +1 -1
- package/node_modules/axios/dist/axios.min.js +2 -2
- package/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/axios/dist/browser/axios.cjs +286 -213
- package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
- package/node_modules/axios/dist/esm/axios.js +286 -213
- package/node_modules/axios/dist/esm/axios.js.map +1 -1
- package/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/axios/dist/node/axios.cjs +377 -213
- package/node_modules/axios/dist/node/axios.cjs.map +1 -1
- package/node_modules/axios/index.d.cts +12 -5
- package/node_modules/axios/index.d.ts +13 -4
- package/node_modules/axios/lib/adapters/adapters.js +6 -4
- package/node_modules/axios/lib/adapters/fetch.js +221 -162
- package/node_modules/axios/lib/adapters/http.js +18 -0
- package/node_modules/axios/lib/adapters/xhr.js +11 -8
- package/node_modules/axios/lib/core/Axios.js +0 -2
- package/node_modules/axios/lib/core/AxiosError.js +10 -3
- package/node_modules/axios/lib/core/dispatchRequest.js +1 -1
- package/node_modules/axios/lib/defaults/index.js +1 -1
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/buildURL.js +1 -3
- package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
- package/node_modules/axios/lib/helpers/resolveConfig.js +13 -9
- package/node_modules/axios/lib/utils.js +5 -3
- package/node_modules/axios/package.json +18 -12
- package/node_modules/balanced-match/.github/FUNDING.yml +2 -0
- package/node_modules/balanced-match/LICENSE.md +21 -0
- package/node_modules/balanced-match/README.md +97 -0
- package/node_modules/balanced-match/index.js +62 -0
- package/node_modules/balanced-match/package.json +48 -0
- package/node_modules/brace-expansion/.github/FUNDING.yml +2 -0
- package/node_modules/brace-expansion/LICENSE +21 -0
- package/node_modules/brace-expansion/README.md +135 -0
- package/node_modules/brace-expansion/index.js +203 -0
- package/node_modules/brace-expansion/package.json +49 -0
- package/node_modules/detect-libc/lib/detect-libc.js +59 -13
- package/node_modules/detect-libc/lib/elf.js +39 -0
- package/node_modules/detect-libc/lib/filesystem.js +18 -8
- package/node_modules/detect-libc/package.json +3 -2
- package/node_modules/minimatch/LICENSE +15 -0
- package/node_modules/minimatch/README.md +454 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +2 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/ast.d.ts +20 -0
- package/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +592 -0
- package/node_modules/minimatch/dist/commonjs/ast.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts +8 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +152 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/escape.d.ts +12 -0
- package/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +22 -0
- package/node_modules/minimatch/dist/commonjs/escape.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/index.d.ts +94 -0
- package/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1017 -0
- package/node_modules/minimatch/dist/commonjs/index.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.d.ts +17 -0
- package/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +24 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +2 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
- package/node_modules/minimatch/dist/esm/ast.d.ts +20 -0
- package/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/ast.js +588 -0
- package/node_modules/minimatch/dist/esm/ast.js.map +1 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.d.ts +8 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +148 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
- package/node_modules/minimatch/dist/esm/escape.d.ts +12 -0
- package/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/escape.js +18 -0
- package/node_modules/minimatch/dist/esm/escape.js.map +1 -0
- package/node_modules/minimatch/dist/esm/index.d.ts +94 -0
- package/node_modules/minimatch/dist/esm/index.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/index.js +1001 -0
- package/node_modules/minimatch/dist/esm/index.js.map +1 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.d.ts +17 -0
- package/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/unescape.js +20 -0
- package/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
- package/node_modules/minimatch/package.json +82 -0
- package/node_modules/node-abi/LICENSE +21 -0
- package/node_modules/node-abi/README.md +54 -0
- package/node_modules/node-abi/abi_registry.json +408 -0
- package/node_modules/node-abi/getNextTarget.js +13 -0
- package/node_modules/node-abi/index.js +161 -0
- package/node_modules/node-abi/package.json +46 -0
- package/node_modules/node-addon-api/README.md +25 -249
- package/node_modules/node-addon-api/common.gypi +1 -0
- package/node_modules/node-addon-api/index.js +2 -0
- package/node_modules/node-addon-api/napi-inl.h +592 -166
- package/node_modules/node-addon-api/napi.h +167 -59
- package/node_modules/node-addon-api/node_addon_api.gyp +10 -0
- package/node_modules/node-addon-api/noexcept.gypi +1 -1
- package/node_modules/node-addon-api/package.json +13 -13
- package/node_modules/node-addon-api/tools/conversion.js +1 -1
- package/node_modules/protobufjs/dist/light/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/light/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/protobuf.min.js +2 -2
- package/node_modules/protobufjs/google/protobuf/descriptor.json +2 -2
- package/node_modules/protobufjs/google/protobuf/descriptor.proto +2 -1
- package/node_modules/protobufjs/package.json +1 -1
- package/node_modules/undici-types/diagnostics-channel.d.ts +9 -0
- package/node_modules/undici-types/dispatcher.d.ts +3 -2
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +2 -1
- package/node_modules/undici-types/eventsource.d.ts +3 -3
- package/node_modules/undici-types/fetch.d.ts +1 -0
- package/node_modules/undici-types/handlers.d.ts +1 -1
- package/node_modules/undici-types/mock-client.d.ts +2 -0
- package/node_modules/undici-types/mock-interceptor.d.ts +2 -0
- package/node_modules/undici-types/mock-pool.d.ts +2 -0
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/retry-handler.d.ts +9 -0
- package/node_modules/undici-types/webidl.d.ts +29 -15
- package/node_modules/undici-types/websocket.d.ts +3 -1
- package/package.json +3 -3
- package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi93.armv8.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi93.glibc.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi93.musl.node +0 -0
- package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi93.node +0 -0
- package/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +0 -111
- package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi93.armv8.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi93.glibc.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi93.musl.node +0 -0
- package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi93.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi93.armv8.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi93.glibc.node +0 -0
- package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi93.node +0 -0
- package/node_modules/@contrast/perf/lib/index.test.js +0 -547
- package/node_modules/@contrast/perf/lib/tsconfig.json +0 -31
- package/node_modules/@contrast/protect/lib/input-tracing/install/spdy.js +0 -63
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/.taprc.yaml +0 -11
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/destroy.test.js +0 -49
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/end.test.js +0 -98
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/flush-sync.test.js +0 -140
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/flush.test.js +0 -419
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/fsync.test.js +0 -63
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/helper.js +0 -42
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/minlength.test.js +0 -35
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/mode.test.js +0 -116
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/reopen.test.js +0 -239
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/retry.test.js +0 -414
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/sync.test.js +0 -261
- package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/write.test.js +0 -465
- package/node_modules/node-addon-api/tools/eslint-format.js +0 -79
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
////////////////////////////////////////////////////////////////////////////////
|
|
10
10
|
|
|
11
11
|
// Note: Do not include this file directly! Include "napi.h" instead.
|
|
12
|
+
// This should be a no-op and is intended for better IDE integration.
|
|
13
|
+
#include "napi.h"
|
|
12
14
|
|
|
13
15
|
#include <algorithm>
|
|
16
|
+
#include <cstdarg>
|
|
14
17
|
#include <cstring>
|
|
15
18
|
#if NAPI_HAS_THREADS
|
|
16
19
|
#include <mutex>
|
|
@@ -32,7 +35,9 @@ namespace details {
|
|
|
32
35
|
constexpr int napi_no_external_buffers_allowed = 22;
|
|
33
36
|
|
|
34
37
|
template <typename FreeType>
|
|
35
|
-
inline void
|
|
38
|
+
inline void default_basic_finalizer(node_addon_api_basic_env /*env*/,
|
|
39
|
+
void* data,
|
|
40
|
+
void* /*hint*/) {
|
|
36
41
|
delete static_cast<FreeType*>(data);
|
|
37
42
|
}
|
|
38
43
|
|
|
@@ -40,8 +45,9 @@ inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
|
|
|
40
45
|
// garbage-collected.
|
|
41
46
|
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
|
|
42
47
|
// available on all supported versions of Node.js.
|
|
43
|
-
template <
|
|
44
|
-
|
|
48
|
+
template <
|
|
49
|
+
typename FreeType,
|
|
50
|
+
node_addon_api_basic_finalize finalizer = default_basic_finalizer<FreeType>>
|
|
45
51
|
inline napi_status AttachData(napi_env env,
|
|
46
52
|
napi_value obj,
|
|
47
53
|
FreeType* data,
|
|
@@ -73,19 +79,33 @@ inline napi_status AttachData(napi_env env,
|
|
|
73
79
|
// For use in JS to C++ callback wrappers to catch any Napi::Error exceptions
|
|
74
80
|
// and rethrow them as JavaScript exceptions before returning from the callback.
|
|
75
81
|
template <typename Callable>
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
83
|
+
inline napi_value WrapCallback(napi_env env, Callable callback) {
|
|
84
|
+
#else
|
|
85
|
+
inline napi_value WrapCallback(napi_env, Callable callback) {
|
|
86
|
+
#endif
|
|
87
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
78
88
|
try {
|
|
79
89
|
return callback();
|
|
80
90
|
} catch (const Error& e) {
|
|
81
91
|
e.ThrowAsJavaScriptException();
|
|
82
92
|
return nullptr;
|
|
83
93
|
}
|
|
84
|
-
#
|
|
94
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
95
|
+
catch (const std::exception& e) {
|
|
96
|
+
Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
|
|
97
|
+
return nullptr;
|
|
98
|
+
} catch (...) {
|
|
99
|
+
Napi::Error::New(env, "A native exception was thrown")
|
|
100
|
+
.ThrowAsJavaScriptException();
|
|
101
|
+
return nullptr;
|
|
102
|
+
}
|
|
103
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
104
|
+
#else // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
85
105
|
// When C++ exceptions are disabled, errors are immediately thrown as JS
|
|
86
106
|
// exceptions, so there is no need to catch and rethrow them here.
|
|
87
107
|
return callback();
|
|
88
|
-
#endif //
|
|
108
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
// For use in JS to C++ void callback wrappers to catch any Napi::Error
|
|
@@ -93,7 +113,7 @@ inline napi_value WrapCallback(Callable callback) {
|
|
|
93
113
|
// the callback.
|
|
94
114
|
template <typename Callable>
|
|
95
115
|
inline void WrapVoidCallback(Callable callback) {
|
|
96
|
-
#ifdef
|
|
116
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
97
117
|
try {
|
|
98
118
|
callback();
|
|
99
119
|
} catch (const Error& e) {
|
|
@@ -106,10 +126,41 @@ inline void WrapVoidCallback(Callable callback) {
|
|
|
106
126
|
#endif // NAPI_CPP_EXCEPTIONS
|
|
107
127
|
}
|
|
108
128
|
|
|
129
|
+
// For use in JS to C++ void callback wrappers to catch _any_ thrown exception
|
|
130
|
+
// and rethrow them as JavaScript exceptions before returning from the callback,
|
|
131
|
+
// wrapping in an Napi::Error as needed.
|
|
132
|
+
template <typename Callable>
|
|
133
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
134
|
+
inline void WrapVoidCallback(napi_env env, Callable callback) {
|
|
135
|
+
#else
|
|
136
|
+
inline void WrapVoidCallback(napi_env, Callable callback) {
|
|
137
|
+
#endif
|
|
138
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
139
|
+
try {
|
|
140
|
+
callback();
|
|
141
|
+
} catch (const Error& e) {
|
|
142
|
+
e.ThrowAsJavaScriptException();
|
|
143
|
+
}
|
|
144
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
145
|
+
catch (const std::exception& e) {
|
|
146
|
+
Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
|
|
147
|
+
} catch (...) {
|
|
148
|
+
Napi::Error::New(env, "A native exception was thrown")
|
|
149
|
+
.ThrowAsJavaScriptException();
|
|
150
|
+
}
|
|
151
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS_ALL
|
|
152
|
+
#else
|
|
153
|
+
// When C++ exceptions are disabled, there is no need to catch and rethrow C++
|
|
154
|
+
// exceptions. JS errors should be thrown with
|
|
155
|
+
// `Error::ThrowAsJavaScriptException`.
|
|
156
|
+
callback();
|
|
157
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
158
|
+
}
|
|
159
|
+
|
|
109
160
|
template <typename Callable, typename Return>
|
|
110
161
|
struct CallbackData {
|
|
111
162
|
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
112
|
-
return details::WrapCallback([&] {
|
|
163
|
+
return details::WrapCallback(env, [&] {
|
|
113
164
|
CallbackInfo callbackInfo(env, info);
|
|
114
165
|
CallbackData* callbackData =
|
|
115
166
|
static_cast<CallbackData*>(callbackInfo.Data());
|
|
@@ -125,7 +176,7 @@ struct CallbackData {
|
|
|
125
176
|
template <typename Callable>
|
|
126
177
|
struct CallbackData<Callable, void> {
|
|
127
178
|
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
128
|
-
return details::WrapCallback([&] {
|
|
179
|
+
return details::WrapCallback(env, [&] {
|
|
129
180
|
CallbackInfo callbackInfo(env, info);
|
|
130
181
|
CallbackData* callbackData =
|
|
131
182
|
static_cast<CallbackData*>(callbackInfo.Data());
|
|
@@ -142,7 +193,7 @@ struct CallbackData<Callable, void> {
|
|
|
142
193
|
template <void (*Callback)(const CallbackInfo& info)>
|
|
143
194
|
napi_value TemplatedVoidCallback(napi_env env,
|
|
144
195
|
napi_callback_info info) NAPI_NOEXCEPT {
|
|
145
|
-
return details::WrapCallback([&] {
|
|
196
|
+
return details::WrapCallback(env, [&] {
|
|
146
197
|
CallbackInfo cbInfo(env, info);
|
|
147
198
|
Callback(cbInfo);
|
|
148
199
|
return nullptr;
|
|
@@ -152,9 +203,12 @@ napi_value TemplatedVoidCallback(napi_env env,
|
|
|
152
203
|
template <Napi::Value (*Callback)(const CallbackInfo& info)>
|
|
153
204
|
napi_value TemplatedCallback(napi_env env,
|
|
154
205
|
napi_callback_info info) NAPI_NOEXCEPT {
|
|
155
|
-
return details::WrapCallback([&] {
|
|
206
|
+
return details::WrapCallback(env, [&] {
|
|
156
207
|
CallbackInfo cbInfo(env, info);
|
|
157
|
-
|
|
208
|
+
// MSVC requires to copy 'Callback' function pointer to a local variable
|
|
209
|
+
// before invoking it.
|
|
210
|
+
auto callback = Callback;
|
|
211
|
+
return callback(cbInfo);
|
|
158
212
|
});
|
|
159
213
|
}
|
|
160
214
|
|
|
@@ -162,7 +216,7 @@ template <typename T,
|
|
|
162
216
|
Napi::Value (T::*UnwrapCallback)(const CallbackInfo& info)>
|
|
163
217
|
napi_value TemplatedInstanceCallback(napi_env env,
|
|
164
218
|
napi_callback_info info) NAPI_NOEXCEPT {
|
|
165
|
-
return details::WrapCallback([&] {
|
|
219
|
+
return details::WrapCallback(env, [&] {
|
|
166
220
|
CallbackInfo cbInfo(env, info);
|
|
167
221
|
T* instance = T::Unwrap(cbInfo.This().As<Object>());
|
|
168
222
|
return instance ? (instance->*UnwrapCallback)(cbInfo) : Napi::Value();
|
|
@@ -172,7 +226,7 @@ napi_value TemplatedInstanceCallback(napi_env env,
|
|
|
172
226
|
template <typename T, void (T::*UnwrapCallback)(const CallbackInfo& info)>
|
|
173
227
|
napi_value TemplatedInstanceVoidCallback(napi_env env, napi_callback_info info)
|
|
174
228
|
NAPI_NOEXCEPT {
|
|
175
|
-
return details::WrapCallback([&] {
|
|
229
|
+
return details::WrapCallback(env, [&] {
|
|
176
230
|
CallbackInfo cbInfo(env, info);
|
|
177
231
|
T* instance = T::Unwrap(cbInfo.This().As<Object>());
|
|
178
232
|
if (instance) (instance->*UnwrapCallback)(cbInfo);
|
|
@@ -182,23 +236,102 @@ napi_value TemplatedInstanceVoidCallback(napi_env env, napi_callback_info info)
|
|
|
182
236
|
|
|
183
237
|
template <typename T, typename Finalizer, typename Hint = void>
|
|
184
238
|
struct FinalizeData {
|
|
185
|
-
|
|
239
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
240
|
+
template <typename F = Finalizer,
|
|
241
|
+
typename = std::enable_if_t<
|
|
242
|
+
std::is_invocable_v<F, node_addon_api_basic_env, T*>>>
|
|
243
|
+
#endif
|
|
244
|
+
static inline void Wrapper(node_addon_api_basic_env env,
|
|
186
245
|
void* data,
|
|
187
246
|
void* finalizeHint) NAPI_NOEXCEPT {
|
|
188
247
|
WrapVoidCallback([&] {
|
|
189
248
|
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
190
|
-
finalizeData->callback(
|
|
249
|
+
finalizeData->callback(env, static_cast<T*>(data));
|
|
191
250
|
delete finalizeData;
|
|
192
251
|
});
|
|
193
252
|
}
|
|
194
253
|
|
|
195
|
-
|
|
254
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
255
|
+
template <typename F = Finalizer,
|
|
256
|
+
typename = std::enable_if_t<
|
|
257
|
+
!std::is_invocable_v<F, node_addon_api_basic_env, T*>>,
|
|
258
|
+
typename = void>
|
|
259
|
+
static inline void Wrapper(node_addon_api_basic_env env,
|
|
260
|
+
void* data,
|
|
261
|
+
void* finalizeHint) NAPI_NOEXCEPT {
|
|
262
|
+
#ifdef NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS
|
|
263
|
+
static_assert(false,
|
|
264
|
+
"NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS defined: Finalizer "
|
|
265
|
+
"must be basic.");
|
|
266
|
+
#endif
|
|
267
|
+
napi_status status =
|
|
268
|
+
node_api_post_finalizer(env, WrapperGC, data, finalizeHint);
|
|
269
|
+
NAPI_FATAL_IF_FAILED(
|
|
270
|
+
status, "FinalizeData::Wrapper", "node_api_post_finalizer failed");
|
|
271
|
+
}
|
|
272
|
+
#endif
|
|
273
|
+
|
|
274
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
275
|
+
template <typename F = Finalizer,
|
|
276
|
+
typename = std::enable_if_t<
|
|
277
|
+
std::is_invocable_v<F, node_addon_api_basic_env, T*, Hint*>>>
|
|
278
|
+
#endif
|
|
279
|
+
static inline void WrapperWithHint(node_addon_api_basic_env env,
|
|
196
280
|
void* data,
|
|
197
281
|
void* finalizeHint) NAPI_NOEXCEPT {
|
|
198
282
|
WrapVoidCallback([&] {
|
|
199
283
|
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
200
|
-
finalizeData->callback(
|
|
201
|
-
|
|
284
|
+
finalizeData->callback(env, static_cast<T*>(data), finalizeData->hint);
|
|
285
|
+
delete finalizeData;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
290
|
+
template <typename F = Finalizer,
|
|
291
|
+
typename = std::enable_if_t<
|
|
292
|
+
!std::is_invocable_v<F, node_addon_api_basic_env, T*, Hint*>>,
|
|
293
|
+
typename = void>
|
|
294
|
+
static inline void WrapperWithHint(node_addon_api_basic_env env,
|
|
295
|
+
void* data,
|
|
296
|
+
void* finalizeHint) NAPI_NOEXCEPT {
|
|
297
|
+
#ifdef NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS
|
|
298
|
+
static_assert(false,
|
|
299
|
+
"NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS defined: Finalizer "
|
|
300
|
+
"must be basic.");
|
|
301
|
+
#endif
|
|
302
|
+
napi_status status =
|
|
303
|
+
node_api_post_finalizer(env, WrapperGCWithHint, data, finalizeHint);
|
|
304
|
+
NAPI_FATAL_IF_FAILED(
|
|
305
|
+
status, "FinalizeData::Wrapper", "node_api_post_finalizer failed");
|
|
306
|
+
}
|
|
307
|
+
#endif
|
|
308
|
+
|
|
309
|
+
static inline void WrapperGCWithoutData(napi_env env,
|
|
310
|
+
void* /*data*/,
|
|
311
|
+
void* finalizeHint) NAPI_NOEXCEPT {
|
|
312
|
+
WrapVoidCallback(env, [&] {
|
|
313
|
+
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
314
|
+
finalizeData->callback(env);
|
|
315
|
+
delete finalizeData;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
static inline void WrapperGC(napi_env env,
|
|
320
|
+
void* data,
|
|
321
|
+
void* finalizeHint) NAPI_NOEXCEPT {
|
|
322
|
+
WrapVoidCallback(env, [&] {
|
|
323
|
+
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
324
|
+
finalizeData->callback(env, static_cast<T*>(data));
|
|
325
|
+
delete finalizeData;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
static inline void WrapperGCWithHint(napi_env env,
|
|
330
|
+
void* data,
|
|
331
|
+
void* finalizeHint) NAPI_NOEXCEPT {
|
|
332
|
+
WrapVoidCallback(env, [&] {
|
|
333
|
+
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
334
|
+
finalizeData->callback(env, static_cast<T*>(data), finalizeData->hint);
|
|
202
335
|
delete finalizeData;
|
|
203
336
|
});
|
|
204
337
|
}
|
|
@@ -263,7 +396,7 @@ struct ThreadSafeFinalize {
|
|
|
263
396
|
template <typename ContextType, typename DataType, typename CallJs, CallJs call>
|
|
264
397
|
inline typename std::enable_if<call != static_cast<CallJs>(nullptr)>::type
|
|
265
398
|
CallJsWrapper(napi_env env, napi_value jsCallback, void* context, void* data) {
|
|
266
|
-
details::WrapVoidCallback([&]() {
|
|
399
|
+
details::WrapVoidCallback(env, [&]() {
|
|
267
400
|
call(env,
|
|
268
401
|
Function(env, jsCallback),
|
|
269
402
|
static_cast<ContextType*>(context),
|
|
@@ -277,7 +410,7 @@ CallJsWrapper(napi_env env,
|
|
|
277
410
|
napi_value jsCallback,
|
|
278
411
|
void* /*context*/,
|
|
279
412
|
void* /*data*/) {
|
|
280
|
-
details::WrapVoidCallback([&]() {
|
|
413
|
+
details::WrapVoidCallback(env, [&]() {
|
|
281
414
|
if (jsCallback != nullptr) {
|
|
282
415
|
Function(env, jsCallback).Call(0, nullptr);
|
|
283
416
|
}
|
|
@@ -311,7 +444,7 @@ template <typename Getter, typename Setter>
|
|
|
311
444
|
struct AccessorCallbackData {
|
|
312
445
|
static inline napi_value GetterWrapper(napi_env env,
|
|
313
446
|
napi_callback_info info) {
|
|
314
|
-
return details::WrapCallback([&] {
|
|
447
|
+
return details::WrapCallback(env, [&] {
|
|
315
448
|
CallbackInfo callbackInfo(env, info);
|
|
316
449
|
AccessorCallbackData* callbackData =
|
|
317
450
|
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -322,7 +455,7 @@ struct AccessorCallbackData {
|
|
|
322
455
|
|
|
323
456
|
static inline napi_value SetterWrapper(napi_env env,
|
|
324
457
|
napi_callback_info info) {
|
|
325
|
-
return details::WrapCallback([&] {
|
|
458
|
+
return details::WrapCallback(env, [&] {
|
|
326
459
|
CallbackInfo callbackInfo(env, info);
|
|
327
460
|
AccessorCallbackData* callbackData =
|
|
328
461
|
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -337,6 +470,46 @@ struct AccessorCallbackData {
|
|
|
337
470
|
void* data;
|
|
338
471
|
};
|
|
339
472
|
|
|
473
|
+
// Debugging-purpose C++-style variant of sprintf().
|
|
474
|
+
inline std::string StringFormat(const char* format, ...) {
|
|
475
|
+
std::string result;
|
|
476
|
+
va_list args;
|
|
477
|
+
va_start(args, format);
|
|
478
|
+
int len = vsnprintf(nullptr, 0, format, args);
|
|
479
|
+
result.resize(len);
|
|
480
|
+
vsnprintf(&result[0], len + 1, format, args);
|
|
481
|
+
va_end(args);
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
template <typename T>
|
|
486
|
+
class HasExtendedFinalizer {
|
|
487
|
+
private:
|
|
488
|
+
template <typename U, void (U::*)(Napi::Env)>
|
|
489
|
+
struct SFINAE {};
|
|
490
|
+
template <typename U>
|
|
491
|
+
static char test(SFINAE<U, &U::Finalize>*);
|
|
492
|
+
template <typename U>
|
|
493
|
+
static int test(...);
|
|
494
|
+
|
|
495
|
+
public:
|
|
496
|
+
static constexpr bool value = sizeof(test<T>(0)) == sizeof(char);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
template <typename T>
|
|
500
|
+
class HasBasicFinalizer {
|
|
501
|
+
private:
|
|
502
|
+
template <typename U, void (U::*)(Napi::BasicEnv)>
|
|
503
|
+
struct SFINAE {};
|
|
504
|
+
template <typename U>
|
|
505
|
+
static char test(SFINAE<U, &U::Finalize>*);
|
|
506
|
+
template <typename U>
|
|
507
|
+
static int test(...);
|
|
508
|
+
|
|
509
|
+
public:
|
|
510
|
+
static constexpr bool value = sizeof(test<T>(0)) == sizeof(char);
|
|
511
|
+
};
|
|
512
|
+
|
|
340
513
|
} // namespace details
|
|
341
514
|
|
|
342
515
|
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
|
|
@@ -373,7 +546,7 @@ struct AccessorCallbackData {
|
|
|
373
546
|
inline napi_value RegisterModule(napi_env env,
|
|
374
547
|
napi_value exports,
|
|
375
548
|
ModuleRegisterCallback registerCallback) {
|
|
376
|
-
return details::WrapCallback([&] {
|
|
549
|
+
return details::WrapCallback(env, [&] {
|
|
377
550
|
return napi_value(
|
|
378
551
|
registerCallback(Napi::Env(env), Napi::Object(env, exports)));
|
|
379
552
|
});
|
|
@@ -446,15 +619,21 @@ inline Maybe<T> Just(const T& t) {
|
|
|
446
619
|
}
|
|
447
620
|
|
|
448
621
|
////////////////////////////////////////////////////////////////////////////////
|
|
449
|
-
// Env class
|
|
622
|
+
// BasicEnv / Env class
|
|
450
623
|
////////////////////////////////////////////////////////////////////////////////
|
|
451
624
|
|
|
452
|
-
inline
|
|
625
|
+
inline BasicEnv::BasicEnv(node_addon_api_basic_env env) : _env(env) {}
|
|
453
626
|
|
|
454
|
-
inline
|
|
627
|
+
inline BasicEnv::operator node_addon_api_basic_env() const {
|
|
455
628
|
return _env;
|
|
456
629
|
}
|
|
457
630
|
|
|
631
|
+
inline Env::Env(napi_env env) : BasicEnv(env) {}
|
|
632
|
+
|
|
633
|
+
inline Env::operator napi_env() const {
|
|
634
|
+
return const_cast<napi_env>(_env);
|
|
635
|
+
}
|
|
636
|
+
|
|
458
637
|
inline Object Env::Global() const {
|
|
459
638
|
napi_value value;
|
|
460
639
|
napi_status status = napi_get_global(*this, &value);
|
|
@@ -478,7 +657,7 @@ inline Value Env::Null() const {
|
|
|
478
657
|
|
|
479
658
|
inline bool Env::IsExceptionPending() const {
|
|
480
659
|
bool result;
|
|
481
|
-
napi_status status = napi_is_exception_pending(
|
|
660
|
+
napi_status status = napi_is_exception_pending(*this, &result);
|
|
482
661
|
if (status != napi_ok)
|
|
483
662
|
result = false; // Checking for a pending exception shouldn't throw.
|
|
484
663
|
return result;
|
|
@@ -486,16 +665,16 @@ inline bool Env::IsExceptionPending() const {
|
|
|
486
665
|
|
|
487
666
|
inline Error Env::GetAndClearPendingException() const {
|
|
488
667
|
napi_value value;
|
|
489
|
-
napi_status status = napi_get_and_clear_last_exception(
|
|
668
|
+
napi_status status = napi_get_and_clear_last_exception(*this, &value);
|
|
490
669
|
if (status != napi_ok) {
|
|
491
670
|
// Don't throw another exception when failing to get the exception!
|
|
492
671
|
return Error();
|
|
493
672
|
}
|
|
494
|
-
return Error(
|
|
673
|
+
return Error(*this, value);
|
|
495
674
|
}
|
|
496
675
|
|
|
497
676
|
inline MaybeOrValue<Value> Env::RunScript(const char* utf8script) const {
|
|
498
|
-
String script = String::New(
|
|
677
|
+
String script = String::New(*this, utf8script);
|
|
499
678
|
return RunScript(script);
|
|
500
679
|
}
|
|
501
680
|
|
|
@@ -505,46 +684,46 @@ inline MaybeOrValue<Value> Env::RunScript(const std::string& utf8script) const {
|
|
|
505
684
|
|
|
506
685
|
inline MaybeOrValue<Value> Env::RunScript(String script) const {
|
|
507
686
|
napi_value result;
|
|
508
|
-
napi_status status = napi_run_script(
|
|
687
|
+
napi_status status = napi_run_script(*this, script, &result);
|
|
509
688
|
NAPI_RETURN_OR_THROW_IF_FAILED(
|
|
510
|
-
|
|
689
|
+
*this, status, Napi::Value(*this, result), Napi::Value);
|
|
511
690
|
}
|
|
512
691
|
|
|
513
692
|
#if NAPI_VERSION > 2
|
|
514
693
|
template <typename Hook, typename Arg>
|
|
515
|
-
void
|
|
516
|
-
auto* cleanupData =
|
|
517
|
-
|
|
518
|
-
data);
|
|
694
|
+
void BasicEnv::CleanupHook<Hook, Arg>::Wrapper(void* data) NAPI_NOEXCEPT {
|
|
695
|
+
auto* cleanupData = static_cast<
|
|
696
|
+
typename Napi::BasicEnv::CleanupHook<Hook, Arg>::CleanupData*>(data);
|
|
519
697
|
cleanupData->hook();
|
|
520
698
|
delete cleanupData;
|
|
521
699
|
}
|
|
522
700
|
|
|
523
701
|
template <typename Hook, typename Arg>
|
|
524
|
-
void
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
702
|
+
void BasicEnv::CleanupHook<Hook, Arg>::WrapperWithArg(void* data)
|
|
703
|
+
NAPI_NOEXCEPT {
|
|
704
|
+
auto* cleanupData = static_cast<
|
|
705
|
+
typename Napi::BasicEnv::CleanupHook<Hook, Arg>::CleanupData*>(data);
|
|
528
706
|
cleanupData->hook(static_cast<Arg*>(cleanupData->arg));
|
|
529
707
|
delete cleanupData;
|
|
530
708
|
}
|
|
531
709
|
#endif // NAPI_VERSION > 2
|
|
532
710
|
|
|
533
711
|
#if NAPI_VERSION > 5
|
|
534
|
-
template <typename T,
|
|
535
|
-
inline void
|
|
712
|
+
template <typename T, BasicEnv::Finalizer<T> fini>
|
|
713
|
+
inline void BasicEnv::SetInstanceData(T* data) const {
|
|
536
714
|
napi_status status = napi_set_instance_data(
|
|
537
715
|
_env,
|
|
538
716
|
data,
|
|
539
717
|
[](napi_env env, void* data, void*) { fini(env, static_cast<T*>(data)); },
|
|
540
718
|
nullptr);
|
|
541
|
-
|
|
719
|
+
NAPI_FATAL_IF_FAILED(
|
|
720
|
+
status, "BasicEnv::SetInstanceData", "invalid arguments");
|
|
542
721
|
}
|
|
543
722
|
|
|
544
723
|
template <typename DataType,
|
|
545
724
|
typename HintType,
|
|
546
|
-
Napi::
|
|
547
|
-
inline void
|
|
725
|
+
Napi::BasicEnv::FinalizerWithHint<DataType, HintType> fini>
|
|
726
|
+
inline void BasicEnv::SetInstanceData(DataType* data, HintType* hint) const {
|
|
548
727
|
napi_status status = napi_set_instance_data(
|
|
549
728
|
_env,
|
|
550
729
|
data,
|
|
@@ -552,35 +731,38 @@ inline void Env::SetInstanceData(DataType* data, HintType* hint) const {
|
|
|
552
731
|
fini(env, static_cast<DataType*>(data), static_cast<HintType*>(hint));
|
|
553
732
|
},
|
|
554
733
|
hint);
|
|
555
|
-
|
|
734
|
+
NAPI_FATAL_IF_FAILED(
|
|
735
|
+
status, "BasicEnv::SetInstanceData", "invalid arguments");
|
|
556
736
|
}
|
|
557
737
|
|
|
558
738
|
template <typename T>
|
|
559
|
-
inline T*
|
|
739
|
+
inline T* BasicEnv::GetInstanceData() const {
|
|
560
740
|
void* data = nullptr;
|
|
561
741
|
|
|
562
742
|
napi_status status = napi_get_instance_data(_env, &data);
|
|
563
|
-
|
|
743
|
+
NAPI_FATAL_IF_FAILED(
|
|
744
|
+
status, "BasicEnv::GetInstanceData", "invalid arguments");
|
|
564
745
|
|
|
565
746
|
return static_cast<T*>(data);
|
|
566
747
|
}
|
|
567
748
|
|
|
568
749
|
template <typename T>
|
|
569
|
-
void
|
|
750
|
+
void BasicEnv::DefaultFini(Env, T* data) {
|
|
570
751
|
delete data;
|
|
571
752
|
}
|
|
572
753
|
|
|
573
754
|
template <typename DataType, typename HintType>
|
|
574
|
-
void
|
|
755
|
+
void BasicEnv::DefaultFiniWithHint(Env, DataType* data, HintType*) {
|
|
575
756
|
delete data;
|
|
576
757
|
}
|
|
577
758
|
#endif // NAPI_VERSION > 5
|
|
578
759
|
|
|
579
760
|
#if NAPI_VERSION > 8
|
|
580
|
-
inline const char*
|
|
761
|
+
inline const char* BasicEnv::GetModuleFileName() const {
|
|
581
762
|
const char* result;
|
|
582
763
|
napi_status status = node_api_get_module_file_name(_env, &result);
|
|
583
|
-
|
|
764
|
+
NAPI_FATAL_IF_FAILED(
|
|
765
|
+
status, "BasicEnv::GetModuleFileName", "invalid arguments");
|
|
584
766
|
return result;
|
|
585
767
|
}
|
|
586
768
|
#endif // NAPI_VERSION > 8
|
|
@@ -760,6 +942,16 @@ inline T Value::As() const {
|
|
|
760
942
|
return T(_env, _value);
|
|
761
943
|
}
|
|
762
944
|
|
|
945
|
+
template <typename T>
|
|
946
|
+
inline T Value::UnsafeAs() const {
|
|
947
|
+
return T(_env, _value);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// static
|
|
951
|
+
inline void Value::CheckCast(napi_env /* env */, napi_value value) {
|
|
952
|
+
NAPI_CHECK(value != nullptr, "Value::CheckCast", "empty value");
|
|
953
|
+
}
|
|
954
|
+
|
|
763
955
|
inline MaybeOrValue<Boolean> Value::ToBoolean() const {
|
|
764
956
|
napi_value result;
|
|
765
957
|
napi_status status = napi_coerce_to_bool(_env, _value, &result);
|
|
@@ -805,8 +997,7 @@ inline void Boolean::CheckCast(napi_env env, napi_value value) {
|
|
|
805
997
|
napi_valuetype type;
|
|
806
998
|
napi_status status = napi_typeof(env, value, &type);
|
|
807
999
|
NAPI_CHECK(status == napi_ok, "Boolean::CheckCast", "napi_typeof failed");
|
|
808
|
-
|
|
809
|
-
type == napi_boolean, "Boolean::CheckCast", "value is not napi_boolean");
|
|
1000
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_boolean, "%d", "Boolean::CheckCast");
|
|
810
1001
|
}
|
|
811
1002
|
|
|
812
1003
|
inline Boolean::Boolean() : Napi::Value() {}
|
|
@@ -842,8 +1033,7 @@ inline void Number::CheckCast(napi_env env, napi_value value) {
|
|
|
842
1033
|
napi_valuetype type;
|
|
843
1034
|
napi_status status = napi_typeof(env, value, &type);
|
|
844
1035
|
NAPI_CHECK(status == napi_ok, "Number::CheckCast", "napi_typeof failed");
|
|
845
|
-
|
|
846
|
-
type == napi_number, "Number::CheckCast", "value is not napi_number");
|
|
1036
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_number, "%d", "Number::CheckCast");
|
|
847
1037
|
}
|
|
848
1038
|
|
|
849
1039
|
inline Number::Number() : Value() {}
|
|
@@ -938,8 +1128,7 @@ inline void BigInt::CheckCast(napi_env env, napi_value value) {
|
|
|
938
1128
|
napi_valuetype type;
|
|
939
1129
|
napi_status status = napi_typeof(env, value, &type);
|
|
940
1130
|
NAPI_CHECK(status == napi_ok, "BigInt::CheckCast", "napi_typeof failed");
|
|
941
|
-
|
|
942
|
-
type == napi_bigint, "BigInt::CheckCast", "value is not napi_bigint");
|
|
1131
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_bigint, "%d", "BigInt::CheckCast");
|
|
943
1132
|
}
|
|
944
1133
|
|
|
945
1134
|
inline BigInt::BigInt() : Value() {}
|
|
@@ -1025,9 +1214,10 @@ inline void Name::CheckCast(napi_env env, napi_value value) {
|
|
|
1025
1214
|
napi_valuetype type;
|
|
1026
1215
|
napi_status status = napi_typeof(env, value, &type);
|
|
1027
1216
|
NAPI_CHECK(status == napi_ok, "Name::CheckCast", "napi_typeof failed");
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1217
|
+
NAPI_INTERNAL_CHECK(type == napi_string || type == napi_symbol,
|
|
1218
|
+
"Name::CheckCast",
|
|
1219
|
+
"value is not napi_string or napi_symbol, got %d.",
|
|
1220
|
+
type);
|
|
1031
1221
|
}
|
|
1032
1222
|
|
|
1033
1223
|
inline Name::Name() : Value() {}
|
|
@@ -1094,8 +1284,7 @@ inline void String::CheckCast(napi_env env, napi_value value) {
|
|
|
1094
1284
|
napi_valuetype type;
|
|
1095
1285
|
napi_status status = napi_typeof(env, value, &type);
|
|
1096
1286
|
NAPI_CHECK(status == napi_ok, "String::CheckCast", "napi_typeof failed");
|
|
1097
|
-
|
|
1098
|
-
type == napi_string, "String::CheckCast", "value is not napi_string");
|
|
1287
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_string, "%d", "String::CheckCast");
|
|
1099
1288
|
}
|
|
1100
1289
|
|
|
1101
1290
|
inline String::String() : Name() {}
|
|
@@ -1170,12 +1359,15 @@ inline Symbol Symbol::New(napi_env env, napi_value description) {
|
|
|
1170
1359
|
|
|
1171
1360
|
inline MaybeOrValue<Symbol> Symbol::WellKnown(napi_env env,
|
|
1172
1361
|
const std::string& name) {
|
|
1362
|
+
// No need to check if the return value is a symbol or undefined.
|
|
1363
|
+
// Well known symbols are definite and it is an develop time error
|
|
1364
|
+
// if the symbol does not exist.
|
|
1173
1365
|
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
|
|
1174
1366
|
Value symbol_obj;
|
|
1175
1367
|
Value symbol_value;
|
|
1176
1368
|
if (Napi::Env(env).Global().Get("Symbol").UnwrapTo(&symbol_obj) &&
|
|
1177
1369
|
symbol_obj.As<Object>().Get(name).UnwrapTo(&symbol_value)) {
|
|
1178
|
-
return Just<Symbol>(symbol_value.
|
|
1370
|
+
return Just<Symbol>(symbol_value.UnsafeAs<Symbol>());
|
|
1179
1371
|
}
|
|
1180
1372
|
return Nothing<Symbol>();
|
|
1181
1373
|
#else
|
|
@@ -1184,7 +1376,7 @@ inline MaybeOrValue<Symbol> Symbol::WellKnown(napi_env env,
|
|
|
1184
1376
|
.Get("Symbol")
|
|
1185
1377
|
.As<Object>()
|
|
1186
1378
|
.Get(name)
|
|
1187
|
-
.
|
|
1379
|
+
.UnsafeAs<Symbol>();
|
|
1188
1380
|
#endif
|
|
1189
1381
|
}
|
|
1190
1382
|
|
|
@@ -1231,8 +1423,7 @@ inline void Symbol::CheckCast(napi_env env, napi_value value) {
|
|
|
1231
1423
|
napi_valuetype type;
|
|
1232
1424
|
napi_status status = napi_typeof(env, value, &type);
|
|
1233
1425
|
NAPI_CHECK(status == napi_ok, "Symbol::CheckCast", "napi_typeof failed");
|
|
1234
|
-
|
|
1235
|
-
type == napi_symbol, "Symbol::CheckCast", "value is not napi_symbol");
|
|
1426
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_symbol, "%d", "Symbol::CheckCast");
|
|
1236
1427
|
}
|
|
1237
1428
|
|
|
1238
1429
|
inline Symbol::Symbol() : Name() {}
|
|
@@ -1386,6 +1577,11 @@ inline Object::PropertyLValue<Key>& Object::PropertyLValue<Key>::operator=(
|
|
|
1386
1577
|
return *this;
|
|
1387
1578
|
}
|
|
1388
1579
|
|
|
1580
|
+
template <typename Key>
|
|
1581
|
+
inline Value Object::PropertyLValue<Key>::AsValue() const {
|
|
1582
|
+
return Value(*this);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1389
1585
|
template <typename Key>
|
|
1390
1586
|
inline Object::PropertyLValue<Key>::PropertyLValue(Object object, Key key)
|
|
1391
1587
|
: _env(object.Env()), _object(object), _key(key) {}
|
|
@@ -1403,8 +1599,10 @@ inline void Object::CheckCast(napi_env env, napi_value value) {
|
|
|
1403
1599
|
napi_valuetype type;
|
|
1404
1600
|
napi_status status = napi_typeof(env, value, &type);
|
|
1405
1601
|
NAPI_CHECK(status == napi_ok, "Object::CheckCast", "napi_typeof failed");
|
|
1406
|
-
|
|
1407
|
-
|
|
1602
|
+
NAPI_INTERNAL_CHECK(type == napi_object || type == napi_function,
|
|
1603
|
+
"Object::CheckCast",
|
|
1604
|
+
"Expect napi_object or napi_function, but got %d.",
|
|
1605
|
+
type);
|
|
1408
1606
|
}
|
|
1409
1607
|
|
|
1410
1608
|
inline Object::Object() : TypeTaggable() {}
|
|
@@ -1660,7 +1858,7 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
|
|
|
1660
1858
|
}
|
|
1661
1859
|
}
|
|
1662
1860
|
|
|
1663
|
-
#ifdef
|
|
1861
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
1664
1862
|
inline Object::const_iterator::const_iterator(const Object* object,
|
|
1665
1863
|
const Type type) {
|
|
1666
1864
|
_object = object;
|
|
@@ -1735,7 +1933,7 @@ Object::iterator::operator*() {
|
|
|
1735
1933
|
PropertyLValue<Value> value = (*_object)[key];
|
|
1736
1934
|
return {key, value};
|
|
1737
1935
|
}
|
|
1738
|
-
#endif //
|
|
1936
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
1739
1937
|
|
|
1740
1938
|
#if NAPI_VERSION >= 8
|
|
1741
1939
|
inline MaybeOrValue<bool> Object::Freeze() const {
|
|
@@ -1814,9 +2012,7 @@ inline void External<T>::CheckCast(napi_env env, napi_value value) {
|
|
|
1814
2012
|
napi_valuetype type;
|
|
1815
2013
|
napi_status status = napi_typeof(env, value, &type);
|
|
1816
2014
|
NAPI_CHECK(status == napi_ok, "External::CheckCast", "napi_typeof failed");
|
|
1817
|
-
|
|
1818
|
-
"External::CheckCast",
|
|
1819
|
-
"value is not napi_external");
|
|
2015
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_external, "%d", "External::CheckCast");
|
|
1820
2016
|
}
|
|
1821
2017
|
|
|
1822
2018
|
template <typename T>
|
|
@@ -2270,12 +2466,13 @@ inline void TypedArrayOf<T>::CheckCast(napi_env env, napi_value value) {
|
|
|
2270
2466
|
"TypedArrayOf::CheckCast",
|
|
2271
2467
|
"napi_is_typedarray failed");
|
|
2272
2468
|
|
|
2273
|
-
|
|
2469
|
+
NAPI_INTERNAL_CHECK(
|
|
2274
2470
|
(type == TypedArrayTypeForPrimitiveType<T>() ||
|
|
2275
2471
|
(type == napi_uint8_clamped_array && std::is_same<T, uint8_t>::value)),
|
|
2276
2472
|
"TypedArrayOf::CheckCast",
|
|
2277
|
-
"Array type must match the template parameter
|
|
2278
|
-
"optionally have the \"clamped\" array type.)"
|
|
2473
|
+
"Array type must match the template parameter, (Uint8 arrays may "
|
|
2474
|
+
"optionally have the \"clamped\" array type.), got %d.",
|
|
2475
|
+
type);
|
|
2279
2476
|
}
|
|
2280
2477
|
|
|
2281
2478
|
template <typename T>
|
|
@@ -2456,9 +2653,7 @@ inline void Function::CheckCast(napi_env env, napi_value value) {
|
|
|
2456
2653
|
napi_valuetype type;
|
|
2457
2654
|
napi_status status = napi_typeof(env, value, &type);
|
|
2458
2655
|
NAPI_CHECK(status == napi_ok, "Function::CheckCast", "napi_typeof failed");
|
|
2459
|
-
|
|
2460
|
-
"Function::CheckCast",
|
|
2461
|
-
"value is not napi_function");
|
|
2656
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_function, "%d", "Function::CheckCast");
|
|
2462
2657
|
}
|
|
2463
2658
|
|
|
2464
2659
|
inline Function::Function() : Object() {}
|
|
@@ -2616,8 +2811,95 @@ inline void Promise::CheckCast(napi_env env, napi_value value) {
|
|
|
2616
2811
|
NAPI_CHECK(result, "Promise::CheckCast", "value is not promise");
|
|
2617
2812
|
}
|
|
2618
2813
|
|
|
2814
|
+
inline Promise::Promise() : Object() {}
|
|
2815
|
+
|
|
2619
2816
|
inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
|
|
2620
2817
|
|
|
2818
|
+
inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
|
|
2819
|
+
EscapableHandleScope scope(_env);
|
|
2820
|
+
#ifdef NODE_ADDON_API_ENABLE_MAYBE
|
|
2821
|
+
Value thenMethod;
|
|
2822
|
+
if (!Get("then").UnwrapTo(&thenMethod)) {
|
|
2823
|
+
return Nothing<Promise>();
|
|
2824
|
+
}
|
|
2825
|
+
MaybeOrValue<Value> result =
|
|
2826
|
+
thenMethod.As<Function>().Call(*this, {onFulfilled});
|
|
2827
|
+
if (result.IsJust()) {
|
|
2828
|
+
return Just(scope.Escape(result.Unwrap()).As<Promise>());
|
|
2829
|
+
}
|
|
2830
|
+
return Nothing<Promise>();
|
|
2831
|
+
#else
|
|
2832
|
+
Function thenMethod = Get("then").As<Function>();
|
|
2833
|
+
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled});
|
|
2834
|
+
if (scope.Env().IsExceptionPending()) {
|
|
2835
|
+
return Promise();
|
|
2836
|
+
}
|
|
2837
|
+
return scope.Escape(result).As<Promise>();
|
|
2838
|
+
#endif
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled,
|
|
2842
|
+
napi_value onRejected) const {
|
|
2843
|
+
EscapableHandleScope scope(_env);
|
|
2844
|
+
#ifdef NODE_ADDON_API_ENABLE_MAYBE
|
|
2845
|
+
Value thenMethod;
|
|
2846
|
+
if (!Get("then").UnwrapTo(&thenMethod)) {
|
|
2847
|
+
return Nothing<Promise>();
|
|
2848
|
+
}
|
|
2849
|
+
MaybeOrValue<Value> result =
|
|
2850
|
+
thenMethod.As<Function>().Call(*this, {onFulfilled, onRejected});
|
|
2851
|
+
if (result.IsJust()) {
|
|
2852
|
+
return Just(scope.Escape(result.Unwrap()).As<Promise>());
|
|
2853
|
+
}
|
|
2854
|
+
return Nothing<Promise>();
|
|
2855
|
+
#else
|
|
2856
|
+
Function thenMethod = Get("then").As<Function>();
|
|
2857
|
+
MaybeOrValue<Value> result =
|
|
2858
|
+
thenMethod.Call(*this, {onFulfilled, onRejected});
|
|
2859
|
+
if (scope.Env().IsExceptionPending()) {
|
|
2860
|
+
return Promise();
|
|
2861
|
+
}
|
|
2862
|
+
return scope.Escape(result).As<Promise>();
|
|
2863
|
+
#endif
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
inline MaybeOrValue<Promise> Promise::Catch(napi_value onRejected) const {
|
|
2867
|
+
EscapableHandleScope scope(_env);
|
|
2868
|
+
#ifdef NODE_ADDON_API_ENABLE_MAYBE
|
|
2869
|
+
Value catchMethod;
|
|
2870
|
+
if (!Get("catch").UnwrapTo(&catchMethod)) {
|
|
2871
|
+
return Nothing<Promise>();
|
|
2872
|
+
}
|
|
2873
|
+
MaybeOrValue<Value> result =
|
|
2874
|
+
catchMethod.As<Function>().Call(*this, {onRejected});
|
|
2875
|
+
if (result.IsJust()) {
|
|
2876
|
+
return Just(scope.Escape(result.Unwrap()).As<Promise>());
|
|
2877
|
+
}
|
|
2878
|
+
return Nothing<Promise>();
|
|
2879
|
+
#else
|
|
2880
|
+
Function catchMethod = Get("catch").As<Function>();
|
|
2881
|
+
MaybeOrValue<Value> result = catchMethod.Call(*this, {onRejected});
|
|
2882
|
+
if (scope.Env().IsExceptionPending()) {
|
|
2883
|
+
return Promise();
|
|
2884
|
+
}
|
|
2885
|
+
return scope.Escape(result).As<Promise>();
|
|
2886
|
+
#endif
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled) const {
|
|
2890
|
+
return Then(static_cast<napi_value>(onFulfilled));
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled,
|
|
2894
|
+
const Function& onRejected) const {
|
|
2895
|
+
return Then(static_cast<napi_value>(onFulfilled),
|
|
2896
|
+
static_cast<napi_value>(onRejected));
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
inline MaybeOrValue<Promise> Promise::Catch(const Function& onRejected) const {
|
|
2900
|
+
return Catch(static_cast<napi_value>(onRejected));
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2621
2903
|
////////////////////////////////////////////////////////////////////////////////
|
|
2622
2904
|
// Buffer<T> class
|
|
2623
2905
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -2731,7 +3013,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2731
3013
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2732
3014
|
// If we can't create an external buffer, we'll just copy the data.
|
|
2733
3015
|
Buffer<T> ret = Buffer<T>::Copy(env, data, length);
|
|
2734
|
-
details::FinalizeData<T, Finalizer>::
|
|
3016
|
+
details::FinalizeData<T, Finalizer>::WrapperGC(env, data, finalizeData);
|
|
2735
3017
|
return ret;
|
|
2736
3018
|
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2737
3019
|
}
|
|
@@ -2766,7 +3048,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2766
3048
|
#endif
|
|
2767
3049
|
// If we can't create an external buffer, we'll just copy the data.
|
|
2768
3050
|
Buffer<T> ret = Buffer<T>::Copy(env, data, length);
|
|
2769
|
-
details::FinalizeData<T, Finalizer, Hint>::
|
|
3051
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperGCWithHint(
|
|
2770
3052
|
env, data, finalizeData);
|
|
2771
3053
|
return ret;
|
|
2772
3054
|
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
@@ -3014,14 +3296,14 @@ inline Error& Error::operator=(const Error& other) {
|
|
|
3014
3296
|
|
|
3015
3297
|
inline const std::string& Error::Message() const NAPI_NOEXCEPT {
|
|
3016
3298
|
if (_message.size() == 0 && _env != nullptr) {
|
|
3017
|
-
#ifdef
|
|
3299
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3018
3300
|
try {
|
|
3019
3301
|
_message = Get("message").As<String>();
|
|
3020
3302
|
} catch (...) {
|
|
3021
3303
|
// Catch all errors here, to include e.g. a std::bad_alloc from
|
|
3022
3304
|
// the std::string::operator=, because this method may not throw.
|
|
3023
3305
|
}
|
|
3024
|
-
#else //
|
|
3306
|
+
#else // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3025
3307
|
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
|
|
3026
3308
|
Napi::Value message_val;
|
|
3027
3309
|
if (Get("message").UnwrapTo(&message_val)) {
|
|
@@ -3030,7 +3312,7 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
|
|
|
3030
3312
|
#else
|
|
3031
3313
|
_message = Get("message").As<String>();
|
|
3032
3314
|
#endif
|
|
3033
|
-
#endif //
|
|
3315
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3034
3316
|
}
|
|
3035
3317
|
return _message;
|
|
3036
3318
|
}
|
|
@@ -3054,7 +3336,12 @@ inline void Error::ThrowAsJavaScriptException() const {
|
|
|
3054
3336
|
|
|
3055
3337
|
status = napi_throw(_env, Value());
|
|
3056
3338
|
|
|
3057
|
-
|
|
3339
|
+
#if (NAPI_VERSION >= 10)
|
|
3340
|
+
napi_status expected_failure_mode = napi_cannot_run_js;
|
|
3341
|
+
#else
|
|
3342
|
+
napi_status expected_failure_mode = napi_pending_exception;
|
|
3343
|
+
#endif
|
|
3344
|
+
if (status == expected_failure_mode) {
|
|
3058
3345
|
// The environment must be terminating as we checked earlier and there
|
|
3059
3346
|
// was no pending exception. In this case continuing will result
|
|
3060
3347
|
// in a fatal error and there is nothing the author has done incorrectly
|
|
@@ -3072,24 +3359,24 @@ inline void Error::ThrowAsJavaScriptException() const {
|
|
|
3072
3359
|
napi_status status = napi_throw(_env, Value());
|
|
3073
3360
|
#endif
|
|
3074
3361
|
|
|
3075
|
-
#ifdef
|
|
3362
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3076
3363
|
if (status != napi_ok) {
|
|
3077
3364
|
throw Error::New(_env);
|
|
3078
3365
|
}
|
|
3079
|
-
#else //
|
|
3366
|
+
#else // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3080
3367
|
NAPI_FATAL_IF_FAILED(
|
|
3081
3368
|
status, "Error::ThrowAsJavaScriptException", "napi_throw");
|
|
3082
|
-
#endif //
|
|
3369
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3083
3370
|
}
|
|
3084
3371
|
}
|
|
3085
3372
|
|
|
3086
|
-
#ifdef
|
|
3373
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3087
3374
|
|
|
3088
3375
|
inline const char* Error::what() const NAPI_NOEXCEPT {
|
|
3089
3376
|
return Message().c_str();
|
|
3090
3377
|
}
|
|
3091
3378
|
|
|
3092
|
-
#endif //
|
|
3379
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
3093
3380
|
|
|
3094
3381
|
inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT {
|
|
3095
3382
|
return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
|
|
@@ -3191,7 +3478,15 @@ template <typename T>
|
|
|
3191
3478
|
inline Reference<T>::~Reference() {
|
|
3192
3479
|
if (_ref != nullptr) {
|
|
3193
3480
|
if (!_suppressDestruct) {
|
|
3481
|
+
// TODO(legendecas): napi_delete_reference should be invoked immediately.
|
|
3482
|
+
// Fix this when https://github.com/nodejs/node/pull/55620 lands.
|
|
3483
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
3484
|
+
Env().PostFinalizer(
|
|
3485
|
+
[](Napi::Env env, napi_ref ref) { napi_delete_reference(env, ref); },
|
|
3486
|
+
_ref);
|
|
3487
|
+
#else
|
|
3194
3488
|
napi_delete_reference(_env, _ref);
|
|
3489
|
+
#endif
|
|
3195
3490
|
}
|
|
3196
3491
|
|
|
3197
3492
|
_ref = nullptr;
|
|
@@ -4350,7 +4645,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
|
|
|
4350
4645
|
template <typename T>
|
|
4351
4646
|
inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
|
|
4352
4647
|
napi_env env, napi_callback_info info) {
|
|
4353
|
-
return details::WrapCallback([&] {
|
|
4648
|
+
return details::WrapCallback(env, [&] {
|
|
4354
4649
|
CallbackInfo callbackInfo(env, info);
|
|
4355
4650
|
InstanceVoidMethodCallbackData* callbackData =
|
|
4356
4651
|
reinterpret_cast<InstanceVoidMethodCallbackData*>(callbackInfo.Data());
|
|
@@ -4365,7 +4660,7 @@ inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
|
|
|
4365
4660
|
template <typename T>
|
|
4366
4661
|
inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
|
|
4367
4662
|
napi_env env, napi_callback_info info) {
|
|
4368
|
-
return details::WrapCallback([&] {
|
|
4663
|
+
return details::WrapCallback(env, [&] {
|
|
4369
4664
|
CallbackInfo callbackInfo(env, info);
|
|
4370
4665
|
InstanceMethodCallbackData* callbackData =
|
|
4371
4666
|
reinterpret_cast<InstanceMethodCallbackData*>(callbackInfo.Data());
|
|
@@ -4379,7 +4674,7 @@ inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
|
|
|
4379
4674
|
template <typename T>
|
|
4380
4675
|
inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
|
|
4381
4676
|
napi_env env, napi_callback_info info) {
|
|
4382
|
-
return details::WrapCallback([&] {
|
|
4677
|
+
return details::WrapCallback(env, [&] {
|
|
4383
4678
|
CallbackInfo callbackInfo(env, info);
|
|
4384
4679
|
InstanceAccessorCallbackData* callbackData =
|
|
4385
4680
|
reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -4393,7 +4688,7 @@ inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
|
|
|
4393
4688
|
template <typename T>
|
|
4394
4689
|
inline napi_value InstanceWrap<T>::InstanceSetterCallbackWrapper(
|
|
4395
4690
|
napi_env env, napi_callback_info info) {
|
|
4396
|
-
return details::WrapCallback([&] {
|
|
4691
|
+
return details::WrapCallback(env, [&] {
|
|
4397
4692
|
CallbackInfo callbackInfo(env, info);
|
|
4398
4693
|
InstanceAccessorCallbackData* callbackData =
|
|
4399
4694
|
reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -4409,7 +4704,7 @@ template <typename T>
|
|
|
4409
4704
|
template <typename InstanceWrap<T>::InstanceSetterCallback method>
|
|
4410
4705
|
inline napi_value InstanceWrap<T>::WrappedMethod(
|
|
4411
4706
|
napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
4412
|
-
return details::WrapCallback([&] {
|
|
4707
|
+
return details::WrapCallback(env, [&] {
|
|
4413
4708
|
const CallbackInfo cbInfo(env, info);
|
|
4414
4709
|
T* instance = T::Unwrap(cbInfo.This().As<Object>());
|
|
4415
4710
|
if (instance) (instance->*method)(cbInfo, cbInfo[0]);
|
|
@@ -4439,7 +4734,7 @@ template <typename T>
|
|
|
4439
4734
|
inline ObjectWrap<T>::~ObjectWrap() {
|
|
4440
4735
|
// If the JS object still exists at this point, remove the finalizer added
|
|
4441
4736
|
// through `napi_wrap()`.
|
|
4442
|
-
if (!IsEmpty()) {
|
|
4737
|
+
if (!IsEmpty() && !_finalized) {
|
|
4443
4738
|
Object object = Value();
|
|
4444
4739
|
// It is not valid to call `napi_remove_wrap()` with an empty `object`.
|
|
4445
4740
|
// This happens e.g. during garbage collection.
|
|
@@ -4791,6 +5086,9 @@ inline Value ObjectWrap<T>::OnCalledAsFunction(
|
|
|
4791
5086
|
template <typename T>
|
|
4792
5087
|
inline void ObjectWrap<T>::Finalize(Napi::Env /*env*/) {}
|
|
4793
5088
|
|
|
5089
|
+
template <typename T>
|
|
5090
|
+
inline void ObjectWrap<T>::Finalize(BasicEnv /*env*/) {}
|
|
5091
|
+
|
|
4794
5092
|
template <typename T>
|
|
4795
5093
|
inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
4796
5094
|
napi_env env, napi_callback_info info) {
|
|
@@ -4801,13 +5099,13 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4801
5099
|
bool isConstructCall = (new_target != nullptr);
|
|
4802
5100
|
if (!isConstructCall) {
|
|
4803
5101
|
return details::WrapCallback(
|
|
4804
|
-
[&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); });
|
|
5102
|
+
env, [&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); });
|
|
4805
5103
|
}
|
|
4806
5104
|
|
|
4807
|
-
napi_value wrapper = details::WrapCallback([&] {
|
|
5105
|
+
napi_value wrapper = details::WrapCallback(env, [&] {
|
|
4808
5106
|
CallbackInfo callbackInfo(env, info);
|
|
4809
5107
|
T* instance = new T(callbackInfo);
|
|
4810
|
-
#ifdef
|
|
5108
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
4811
5109
|
instance->_construction_failed = false;
|
|
4812
5110
|
#else
|
|
4813
5111
|
if (callbackInfo.Env().IsExceptionPending()) {
|
|
@@ -4818,7 +5116,7 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4818
5116
|
} else {
|
|
4819
5117
|
instance->_construction_failed = false;
|
|
4820
5118
|
}
|
|
4821
|
-
#endif //
|
|
5119
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
4822
5120
|
return callbackInfo.This();
|
|
4823
5121
|
});
|
|
4824
5122
|
|
|
@@ -4828,7 +5126,7 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4828
5126
|
template <typename T>
|
|
4829
5127
|
inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
|
|
4830
5128
|
napi_env env, napi_callback_info info) {
|
|
4831
|
-
return details::WrapCallback([&] {
|
|
5129
|
+
return details::WrapCallback(env, [&] {
|
|
4832
5130
|
CallbackInfo callbackInfo(env, info);
|
|
4833
5131
|
StaticVoidMethodCallbackData* callbackData =
|
|
4834
5132
|
reinterpret_cast<StaticVoidMethodCallbackData*>(callbackInfo.Data());
|
|
@@ -4841,7 +5139,7 @@ inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
|
|
|
4841
5139
|
template <typename T>
|
|
4842
5140
|
inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
|
|
4843
5141
|
napi_env env, napi_callback_info info) {
|
|
4844
|
-
return details::WrapCallback([&] {
|
|
5142
|
+
return details::WrapCallback(env, [&] {
|
|
4845
5143
|
CallbackInfo callbackInfo(env, info);
|
|
4846
5144
|
StaticMethodCallbackData* callbackData =
|
|
4847
5145
|
reinterpret_cast<StaticMethodCallbackData*>(callbackInfo.Data());
|
|
@@ -4853,7 +5151,7 @@ inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
|
|
|
4853
5151
|
template <typename T>
|
|
4854
5152
|
inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
|
|
4855
5153
|
napi_env env, napi_callback_info info) {
|
|
4856
|
-
return details::WrapCallback([&] {
|
|
5154
|
+
return details::WrapCallback(env, [&] {
|
|
4857
5155
|
CallbackInfo callbackInfo(env, info);
|
|
4858
5156
|
StaticAccessorCallbackData* callbackData =
|
|
4859
5157
|
reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -4865,7 +5163,7 @@ inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
|
|
|
4865
5163
|
template <typename T>
|
|
4866
5164
|
inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
|
|
4867
5165
|
napi_env env, napi_callback_info info) {
|
|
4868
|
-
return details::WrapCallback([&] {
|
|
5166
|
+
return details::WrapCallback(env, [&] {
|
|
4869
5167
|
CallbackInfo callbackInfo(env, info);
|
|
4870
5168
|
StaticAccessorCallbackData* callbackData =
|
|
4871
5169
|
reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
|
|
@@ -4876,10 +5174,61 @@ inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
|
|
|
4876
5174
|
}
|
|
4877
5175
|
|
|
4878
5176
|
template <typename T>
|
|
4879
|
-
inline void ObjectWrap<T>::FinalizeCallback(
|
|
5177
|
+
inline void ObjectWrap<T>::FinalizeCallback(node_addon_api_basic_env env,
|
|
4880
5178
|
void* data,
|
|
4881
5179
|
void* /*hint*/) {
|
|
4882
|
-
|
|
5180
|
+
// If the child class does not override _any_ Finalize() method, `env` will be
|
|
5181
|
+
// unused because of the constexpr guards. Explicitly reference it here to
|
|
5182
|
+
// bypass compiler warnings.
|
|
5183
|
+
(void)env;
|
|
5184
|
+
T* instance = static_cast<T*>(data);
|
|
5185
|
+
|
|
5186
|
+
// Prevent ~ObjectWrap from calling napi_remove_wrap.
|
|
5187
|
+
// The instance->_ref should be deleted with napi_delete_reference in
|
|
5188
|
+
// ~Reference.
|
|
5189
|
+
instance->_finalized = true;
|
|
5190
|
+
|
|
5191
|
+
// If class overrides the basic finalizer, execute it.
|
|
5192
|
+
if constexpr (details::HasBasicFinalizer<T>::value) {
|
|
5193
|
+
#ifndef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
5194
|
+
HandleScope scope(env);
|
|
5195
|
+
#endif
|
|
5196
|
+
|
|
5197
|
+
instance->Finalize(Napi::BasicEnv(env));
|
|
5198
|
+
}
|
|
5199
|
+
|
|
5200
|
+
// If class overrides the (extended) finalizer, either schedule it or
|
|
5201
|
+
// execute it immediately (depending on experimental features enabled).
|
|
5202
|
+
if constexpr (details::HasExtendedFinalizer<T>::value) {
|
|
5203
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
5204
|
+
// In experimental, attach via node_api_post_finalizer.
|
|
5205
|
+
// `PostFinalizeCallback` is responsible for deleting the `T* instance`,
|
|
5206
|
+
// after calling the user-provided finalizer.
|
|
5207
|
+
napi_status status =
|
|
5208
|
+
node_api_post_finalizer(env, PostFinalizeCallback, data, nullptr);
|
|
5209
|
+
NAPI_FATAL_IF_FAILED(status,
|
|
5210
|
+
"ObjectWrap<T>::FinalizeCallback",
|
|
5211
|
+
"node_api_post_finalizer failed");
|
|
5212
|
+
#else
|
|
5213
|
+
// In non-experimental, this `FinalizeCallback` already executes from a
|
|
5214
|
+
// non-basic environment. Execute the override directly.
|
|
5215
|
+
// `PostFinalizeCallback` is responsible for deleting the `T* instance`,
|
|
5216
|
+
// after calling the user-provided finalizer.
|
|
5217
|
+
HandleScope scope(env);
|
|
5218
|
+
PostFinalizeCallback(env, data, static_cast<void*>(nullptr));
|
|
5219
|
+
#endif
|
|
5220
|
+
}
|
|
5221
|
+
// If the instance does _not_ override the (extended) finalizer, delete the
|
|
5222
|
+
// `T* instance` immediately.
|
|
5223
|
+
else {
|
|
5224
|
+
delete instance;
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5227
|
+
|
|
5228
|
+
template <typename T>
|
|
5229
|
+
inline void ObjectWrap<T>::PostFinalizeCallback(napi_env env,
|
|
5230
|
+
void* data,
|
|
5231
|
+
void* /*hint*/) {
|
|
4883
5232
|
T* instance = static_cast<T*>(data);
|
|
4884
5233
|
instance->Finalize(Napi::Env(env));
|
|
4885
5234
|
delete instance;
|
|
@@ -4889,9 +5238,12 @@ template <typename T>
|
|
|
4889
5238
|
template <typename ObjectWrap<T>::StaticSetterCallback method>
|
|
4890
5239
|
inline napi_value ObjectWrap<T>::WrappedMethod(
|
|
4891
5240
|
napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
4892
|
-
return details::WrapCallback([&] {
|
|
5241
|
+
return details::WrapCallback(env, [&] {
|
|
4893
5242
|
const CallbackInfo cbInfo(env, info);
|
|
4894
|
-
method
|
|
5243
|
+
// MSVC requires to copy 'method' function pointer to a local variable
|
|
5244
|
+
// before invoking it.
|
|
5245
|
+
auto m = method;
|
|
5246
|
+
m(cbInfo, cbInfo[0]);
|
|
4895
5247
|
return nullptr;
|
|
4896
5248
|
});
|
|
4897
5249
|
}
|
|
@@ -5187,15 +5539,15 @@ inline void AsyncWorker::OnAsyncWorkExecute(napi_env env, void* asyncworker) {
|
|
|
5187
5539
|
// must not run any method that would cause JavaScript to run. In practice,
|
|
5188
5540
|
// this means that almost any use of napi_env will be incorrect.
|
|
5189
5541
|
inline void AsyncWorker::OnExecute(Napi::Env /*DO_NOT_USE*/) {
|
|
5190
|
-
#ifdef
|
|
5542
|
+
#ifdef NODE_ADDON_API_CPP_EXCEPTIONS
|
|
5191
5543
|
try {
|
|
5192
5544
|
Execute();
|
|
5193
5545
|
} catch (const std::exception& e) {
|
|
5194
5546
|
SetError(e.what());
|
|
5195
5547
|
}
|
|
5196
|
-
#else //
|
|
5548
|
+
#else // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
5197
5549
|
Execute();
|
|
5198
|
-
#endif //
|
|
5550
|
+
#endif // NODE_ADDON_API_CPP_EXCEPTIONS
|
|
5199
5551
|
}
|
|
5200
5552
|
|
|
5201
5553
|
inline void AsyncWorker::OnAsyncWorkComplete(napi_env env,
|
|
@@ -5204,10 +5556,10 @@ inline void AsyncWorker::OnAsyncWorkComplete(napi_env env,
|
|
|
5204
5556
|
AsyncWorker* self = static_cast<AsyncWorker*>(asyncworker);
|
|
5205
5557
|
self->OnWorkComplete(env, status);
|
|
5206
5558
|
}
|
|
5207
|
-
inline void AsyncWorker::OnWorkComplete(Napi::Env
|
|
5559
|
+
inline void AsyncWorker::OnWorkComplete(Napi::Env env, napi_status status) {
|
|
5208
5560
|
if (status != napi_cancelled) {
|
|
5209
5561
|
HandleScope scope(_env);
|
|
5210
|
-
details::WrapCallback([&] {
|
|
5562
|
+
details::WrapCallback(env, [&] {
|
|
5211
5563
|
if (_error.size() == 0) {
|
|
5212
5564
|
OnOK();
|
|
5213
5565
|
} else {
|
|
@@ -5321,19 +5673,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5321
5673
|
auto* finalizeData = new details::
|
|
5322
5674
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5323
5675
|
{data, finalizeCallback});
|
|
5324
|
-
|
|
5325
|
-
env,
|
|
5326
|
-
nullptr,
|
|
5327
|
-
nullptr,
|
|
5328
|
-
String::From(env, resourceName),
|
|
5329
|
-
maxQueueSize,
|
|
5330
|
-
initialThreadCount,
|
|
5331
|
-
finalizeData,
|
|
5676
|
+
auto fini =
|
|
5332
5677
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5333
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5678
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5679
|
+
napi_status status =
|
|
5680
|
+
napi_create_threadsafe_function(env,
|
|
5681
|
+
nullptr,
|
|
5682
|
+
nullptr,
|
|
5683
|
+
String::From(env, resourceName),
|
|
5684
|
+
maxQueueSize,
|
|
5685
|
+
initialThreadCount,
|
|
5686
|
+
finalizeData,
|
|
5687
|
+
fini,
|
|
5688
|
+
context,
|
|
5689
|
+
CallJsInternal,
|
|
5690
|
+
&tsfn._tsfn);
|
|
5337
5691
|
if (status != napi_ok) {
|
|
5338
5692
|
delete finalizeData;
|
|
5339
5693
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5365,19 +5719,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5365
5719
|
auto* finalizeData = new details::
|
|
5366
5720
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5367
5721
|
{data, finalizeCallback});
|
|
5368
|
-
|
|
5369
|
-
env,
|
|
5370
|
-
nullptr,
|
|
5371
|
-
resource,
|
|
5372
|
-
String::From(env, resourceName),
|
|
5373
|
-
maxQueueSize,
|
|
5374
|
-
initialThreadCount,
|
|
5375
|
-
finalizeData,
|
|
5722
|
+
auto fini =
|
|
5376
5723
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5377
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5724
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5725
|
+
napi_status status =
|
|
5726
|
+
napi_create_threadsafe_function(env,
|
|
5727
|
+
nullptr,
|
|
5728
|
+
resource,
|
|
5729
|
+
String::From(env, resourceName),
|
|
5730
|
+
maxQueueSize,
|
|
5731
|
+
initialThreadCount,
|
|
5732
|
+
finalizeData,
|
|
5733
|
+
fini,
|
|
5734
|
+
context,
|
|
5735
|
+
CallJsInternal,
|
|
5736
|
+
&tsfn._tsfn);
|
|
5381
5737
|
if (status != napi_ok) {
|
|
5382
5738
|
delete finalizeData;
|
|
5383
5739
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5481,19 +5837,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5481
5837
|
auto* finalizeData = new details::
|
|
5482
5838
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5483
5839
|
{data, finalizeCallback});
|
|
5484
|
-
|
|
5485
|
-
env,
|
|
5486
|
-
callback,
|
|
5487
|
-
nullptr,
|
|
5488
|
-
String::From(env, resourceName),
|
|
5489
|
-
maxQueueSize,
|
|
5490
|
-
initialThreadCount,
|
|
5491
|
-
finalizeData,
|
|
5840
|
+
auto fini =
|
|
5492
5841
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5493
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5842
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5843
|
+
napi_status status =
|
|
5844
|
+
napi_create_threadsafe_function(env,
|
|
5845
|
+
callback,
|
|
5846
|
+
nullptr,
|
|
5847
|
+
String::From(env, resourceName),
|
|
5848
|
+
maxQueueSize,
|
|
5849
|
+
initialThreadCount,
|
|
5850
|
+
finalizeData,
|
|
5851
|
+
fini,
|
|
5852
|
+
context,
|
|
5853
|
+
CallJsInternal,
|
|
5854
|
+
&tsfn._tsfn);
|
|
5497
5855
|
if (status != napi_ok) {
|
|
5498
5856
|
delete finalizeData;
|
|
5499
5857
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5527,6 +5885,9 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5527
5885
|
auto* finalizeData = new details::
|
|
5528
5886
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5529
5887
|
{data, finalizeCallback});
|
|
5888
|
+
auto fini =
|
|
5889
|
+
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5890
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5530
5891
|
napi_status status = napi_create_threadsafe_function(
|
|
5531
5892
|
env,
|
|
5532
5893
|
details::DefaultCallbackWrapper<
|
|
@@ -5538,8 +5899,7 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5538
5899
|
maxQueueSize,
|
|
5539
5900
|
initialThreadCount,
|
|
5540
5901
|
finalizeData,
|
|
5541
|
-
|
|
5542
|
-
FinalizeFinalizeWrapperWithDataAndContext,
|
|
5902
|
+
fini,
|
|
5543
5903
|
context,
|
|
5544
5904
|
CallJsInternal,
|
|
5545
5905
|
&tsfn._tsfn);
|
|
@@ -6111,7 +6471,7 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
|
|
|
6111
6471
|
return;
|
|
6112
6472
|
}
|
|
6113
6473
|
|
|
6114
|
-
details::WrapVoidCallback([&]() {
|
|
6474
|
+
details::WrapVoidCallback(env, [&]() {
|
|
6115
6475
|
if (data != nullptr) {
|
|
6116
6476
|
auto* callbackWrapper = static_cast<CallbackWrapper*>(data);
|
|
6117
6477
|
(*callbackWrapper)(env, Function(env, jsCallback));
|
|
@@ -6480,12 +6840,14 @@ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
|
|
|
6480
6840
|
// Memory Management class
|
|
6481
6841
|
////////////////////////////////////////////////////////////////////////////////
|
|
6482
6842
|
|
|
6483
|
-
inline int64_t MemoryManagement::AdjustExternalMemory(
|
|
6843
|
+
inline int64_t MemoryManagement::AdjustExternalMemory(BasicEnv env,
|
|
6484
6844
|
int64_t change_in_bytes) {
|
|
6485
6845
|
int64_t result;
|
|
6486
6846
|
napi_status status =
|
|
6487
6847
|
napi_adjust_external_memory(env, change_in_bytes, &result);
|
|
6488
|
-
|
|
6848
|
+
NAPI_FATAL_IF_FAILED(status,
|
|
6849
|
+
"MemoryManagement::AdjustExternalMemory",
|
|
6850
|
+
"napi_adjust_external_memory");
|
|
6489
6851
|
return result;
|
|
6490
6852
|
}
|
|
6491
6853
|
|
|
@@ -6493,17 +6855,20 @@ inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
|
|
|
6493
6855
|
// Version Management class
|
|
6494
6856
|
////////////////////////////////////////////////////////////////////////////////
|
|
6495
6857
|
|
|
6496
|
-
inline uint32_t VersionManagement::GetNapiVersion(
|
|
6858
|
+
inline uint32_t VersionManagement::GetNapiVersion(BasicEnv env) {
|
|
6497
6859
|
uint32_t result;
|
|
6498
6860
|
napi_status status = napi_get_version(env, &result);
|
|
6499
|
-
|
|
6861
|
+
NAPI_FATAL_IF_FAILED(
|
|
6862
|
+
status, "VersionManagement::GetNapiVersion", "napi_get_version");
|
|
6500
6863
|
return result;
|
|
6501
6864
|
}
|
|
6502
6865
|
|
|
6503
|
-
inline const napi_node_version* VersionManagement::GetNodeVersion(
|
|
6866
|
+
inline const napi_node_version* VersionManagement::GetNodeVersion(
|
|
6867
|
+
BasicEnv env) {
|
|
6504
6868
|
const napi_node_version* result;
|
|
6505
6869
|
napi_status status = napi_get_node_version(env, &result);
|
|
6506
|
-
|
|
6870
|
+
NAPI_FATAL_IF_FAILED(
|
|
6871
|
+
status, "VersionManagement::GetNodeVersion", "napi_get_node_version");
|
|
6507
6872
|
return result;
|
|
6508
6873
|
}
|
|
6509
6874
|
|
|
@@ -6548,12 +6913,12 @@ inline Napi::Object Addon<T>::DefineProperties(
|
|
|
6548
6913
|
|
|
6549
6914
|
#if NAPI_VERSION > 2
|
|
6550
6915
|
template <typename Hook, typename Arg>
|
|
6551
|
-
Env::CleanupHook<Hook, Arg>
|
|
6916
|
+
Env::CleanupHook<Hook, Arg> BasicEnv::AddCleanupHook(Hook hook, Arg* arg) {
|
|
6552
6917
|
return CleanupHook<Hook, Arg>(*this, hook, arg);
|
|
6553
6918
|
}
|
|
6554
6919
|
|
|
6555
6920
|
template <typename Hook>
|
|
6556
|
-
Env::CleanupHook<Hook>
|
|
6921
|
+
Env::CleanupHook<Hook> BasicEnv::AddCleanupHook(Hook hook) {
|
|
6557
6922
|
return CleanupHook<Hook>(*this, hook);
|
|
6558
6923
|
}
|
|
6559
6924
|
|
|
@@ -6563,7 +6928,7 @@ Env::CleanupHook<Hook, Arg>::CleanupHook() {
|
|
|
6563
6928
|
}
|
|
6564
6929
|
|
|
6565
6930
|
template <typename Hook, typename Arg>
|
|
6566
|
-
Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::
|
|
6931
|
+
Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::BasicEnv env, Hook hook)
|
|
6567
6932
|
: wrapper(Env::CleanupHook<Hook, Arg>::Wrapper) {
|
|
6568
6933
|
data = new CleanupData{std::move(hook), nullptr};
|
|
6569
6934
|
napi_status status = napi_add_env_cleanup_hook(env, wrapper, data);
|
|
@@ -6574,7 +6939,9 @@ Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::Env env, Hook hook)
|
|
|
6574
6939
|
}
|
|
6575
6940
|
|
|
6576
6941
|
template <typename Hook, typename Arg>
|
|
6577
|
-
Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::
|
|
6942
|
+
Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::BasicEnv env,
|
|
6943
|
+
Hook hook,
|
|
6944
|
+
Arg* arg)
|
|
6578
6945
|
: wrapper(Env::CleanupHook<Hook, Arg>::WrapperWithArg) {
|
|
6579
6946
|
data = new CleanupData{std::move(hook), arg};
|
|
6580
6947
|
napi_status status = napi_add_env_cleanup_hook(env, wrapper, data);
|
|
@@ -6585,7 +6952,7 @@ Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::Env env, Hook hook, Arg* arg)
|
|
|
6585
6952
|
}
|
|
6586
6953
|
|
|
6587
6954
|
template <class Hook, class Arg>
|
|
6588
|
-
bool Env::CleanupHook<Hook, Arg>::Remove(
|
|
6955
|
+
bool Env::CleanupHook<Hook, Arg>::Remove(BasicEnv env) {
|
|
6589
6956
|
napi_status status = napi_remove_env_cleanup_hook(env, wrapper, data);
|
|
6590
6957
|
delete data;
|
|
6591
6958
|
data = nullptr;
|
|
@@ -6598,6 +6965,65 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
|
|
|
6598
6965
|
}
|
|
6599
6966
|
#endif // NAPI_VERSION > 2
|
|
6600
6967
|
|
|
6968
|
+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
6969
|
+
template <typename FinalizerType>
|
|
6970
|
+
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback) const {
|
|
6971
|
+
using T = void*;
|
|
6972
|
+
details::FinalizeData<T, FinalizerType>* finalizeData =
|
|
6973
|
+
new details::FinalizeData<T, FinalizerType>(
|
|
6974
|
+
{std::move(finalizeCallback), nullptr});
|
|
6975
|
+
|
|
6976
|
+
napi_status status = node_api_post_finalizer(
|
|
6977
|
+
_env,
|
|
6978
|
+
details::FinalizeData<T, FinalizerType>::WrapperGCWithoutData,
|
|
6979
|
+
static_cast<void*>(nullptr),
|
|
6980
|
+
finalizeData);
|
|
6981
|
+
if (status != napi_ok) {
|
|
6982
|
+
delete finalizeData;
|
|
6983
|
+
NAPI_FATAL_IF_FAILED(
|
|
6984
|
+
status, "BasicEnv::PostFinalizer", "invalid arguments");
|
|
6985
|
+
}
|
|
6986
|
+
}
|
|
6987
|
+
|
|
6988
|
+
template <typename FinalizerType, typename T>
|
|
6989
|
+
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
|
|
6990
|
+
T* data) const {
|
|
6991
|
+
details::FinalizeData<T, FinalizerType>* finalizeData =
|
|
6992
|
+
new details::FinalizeData<T, FinalizerType>(
|
|
6993
|
+
{std::move(finalizeCallback), nullptr});
|
|
6994
|
+
|
|
6995
|
+
napi_status status = node_api_post_finalizer(
|
|
6996
|
+
_env,
|
|
6997
|
+
details::FinalizeData<T, FinalizerType>::WrapperGC,
|
|
6998
|
+
data,
|
|
6999
|
+
finalizeData);
|
|
7000
|
+
if (status != napi_ok) {
|
|
7001
|
+
delete finalizeData;
|
|
7002
|
+
NAPI_FATAL_IF_FAILED(
|
|
7003
|
+
status, "BasicEnv::PostFinalizer", "invalid arguments");
|
|
7004
|
+
}
|
|
7005
|
+
}
|
|
7006
|
+
|
|
7007
|
+
template <typename FinalizerType, typename T, typename Hint>
|
|
7008
|
+
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
|
|
7009
|
+
T* data,
|
|
7010
|
+
Hint* finalizeHint) const {
|
|
7011
|
+
details::FinalizeData<T, FinalizerType, Hint>* finalizeData =
|
|
7012
|
+
new details::FinalizeData<T, FinalizerType, Hint>(
|
|
7013
|
+
{std::move(finalizeCallback), finalizeHint});
|
|
7014
|
+
napi_status status = node_api_post_finalizer(
|
|
7015
|
+
_env,
|
|
7016
|
+
details::FinalizeData<T, FinalizerType, Hint>::WrapperGCWithHint,
|
|
7017
|
+
data,
|
|
7018
|
+
finalizeData);
|
|
7019
|
+
if (status != napi_ok) {
|
|
7020
|
+
delete finalizeData;
|
|
7021
|
+
NAPI_FATAL_IF_FAILED(
|
|
7022
|
+
status, "BasicEnv::PostFinalizer", "invalid arguments");
|
|
7023
|
+
}
|
|
7024
|
+
}
|
|
7025
|
+
#endif // NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
|
|
7026
|
+
|
|
6601
7027
|
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
|
|
6602
7028
|
} // namespace NAPI_CPP_CUSTOM_NAMESPACE
|
|
6603
7029
|
#endif
|