diff --git a/configure.py b/configure.py index 04a7db46856016..a26d41e898fca3 100755 --- a/configure.py +++ b/configure.py @@ -1481,6 +1481,17 @@ def set_configuration_variable(configs, name, release=None, debug=None): configs['Release']['variables'][name] = release configs['Debug']['variables'][name] = debug +def set_configuration_variable_and_defines(configs, name, release=None, debug=None, release_define=None, debug_define=None): + set_configuration_variable(configs, name, release, debug) + if configs['Debug'].get('defines') is None: + configs['Debug']['defines'] = [] + if configs['Release'].get('defines') is None: + configs['Release']['defines'] = [] + if debug_define: + configs['Debug']['defines'].append(debug_define) + if release_define: + configs['Release']['defines'].append(release_define) + def configure_arm(o): if options.arm_float_abi: arm_float_abi = options.arm_float_abi @@ -1817,7 +1828,14 @@ def configure_rust(o, configs): def configure_v8(o, configs): - set_configuration_variable(configs, 'v8_enable_v8_checks', release=1, debug=0) + set_configuration_variable_and_defines( + configs, + 'v8_enable_v8_checks', + release='0', + debug='1', + release_define=None, + debug_define='V8_ENABLE_CHECKS', + ) o['variables']['v8_enable_webassembly'] = 0 if options.v8_lite_mode else 1 o['variables']['v8_enable_javascript_promise_hooks'] = 1 diff --git a/doc/api/util.md b/doc/api/util.md index 9a02eb43c45b76..031062ba5d6ea4 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -548,7 +548,7 @@ changes: > Stability: 1.1 - Active development -* `frameCount` {number} Optional number of frames to capture as call site objects. +* `frameCount` {integer} Optional number of frames to capture as call site objects. **Default:** `10`. Allowable range is between 1 and 200. * `options` {Object} Optional * `sourceMap` {boolean} Reconstruct the original location in the stacktrace from the source-map. diff --git a/lib/util.js b/lib/util.js index 7c75615e5c70da..5e185f13f00ce7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -66,6 +66,7 @@ const { validateString, validateOneOf, validateObject, + validateInteger, } = require('internal/validators'); const { isReadableStream, @@ -451,7 +452,7 @@ function getCallSites(frameCount = 10, options) { } // Using kDefaultMaxCallStackSizeToCapture as reference - validateNumber(frameCount, 'frameCount', 1, 200); + validateInteger(frameCount, 'frameCount', 1, 200); // If options.sourceMaps is true or if sourceMaps are enabled but the option.sourceMaps is not set explictly to false if (options.sourceMap === true || (getOptionValue('--enable-source-maps') && options.sourceMap !== false)) { return mapCallSite(binding.getCallSites(frameCount)); diff --git a/src/heap_utils.cc b/src/heap_utils.cc index 7b93698c7fe125..98bab1c5404fe2 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -89,7 +89,7 @@ class JSGraph : public EmbedderGraph { } Node* V8Node(const Local& value) override { - return V8Node(value.As()); + return V8Node(v8::Local(value)); } Node* AddNode(std::unique_ptr node) override { diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 2a77bf6d7a4715..93295d83f9676d 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -9,6 +9,7 @@ #include "quic/guard.h" #include "simdutf.h" #include "util-inl.h" +#include "v8-value.h" namespace node { namespace builtins { @@ -441,7 +442,7 @@ void BuiltinLoader::SaveCodeCache(const std::string& id, Local data) { new_cached_data.reset( ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript())); } else { - Local fun = data.As(); + Local fun = data.As().As(); new_cached_data.reset(ScriptCompiler::CreateCodeCacheForFunction(fun)); } CHECK_NOT_NULL(new_cached_data); diff --git a/src/node_util.cc b/src/node_util.cc index 2e4d98a8a66a18..ff43d2aeca86f2 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -258,7 +258,7 @@ static void GetCallSites(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(context); CHECK_EQ(args.Length(), 1); - CHECK(args[0]->IsNumber()); + CHECK(args[0]->IsUint32()); const uint32_t frames = args[0].As()->Value(); CHECK(frames >= 1 && frames <= 200); diff --git a/src/util-inl.h b/src/util-inl.h index 6898e8ea794675..f8cccfef6b65b3 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -22,6 +22,7 @@ #ifndef SRC_UTIL_INL_H_ #define SRC_UTIL_INL_H_ +#include "v8-isolate.h" #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include @@ -678,10 +679,15 @@ T FromV8Value(v8::Local value) { "Type is out of unsigned integer range"); if constexpr (!loose) { CHECK(value->IsUint32()); + return static_cast(value.As()->Value()); } else { CHECK(value->IsNumber()); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local context = isolate->GetCurrentContext(); + v8::Maybe maybe = value->Uint32Value(context); + CHECK(!maybe.IsNothing()); + return static_cast(maybe.FromJust()); } - return static_cast(value.As()->Value()); } else if constexpr (std::is_integral_v && std::is_signed_v) { static_assert( std::numeric_limits::max() <= std::numeric_limits::max() && diff --git a/test/parallel/test-util-getcallsites.js b/test/parallel/test-util-getcallsites.js index 7cab4f6cac6397..a14fcb3482cdf9 100644 --- a/test/parallel/test-util-getcallsites.js +++ b/test/parallel/test-util-getcallsites.js @@ -31,15 +31,14 @@ const assert = require('node:assert'); ); } -// Guarantee dot-right numbers are ignored +// frameCount must be an integer { - const callSites = getCallSites(3.6); - assert.strictEqual(callSites.length, 3); -} - -{ - const callSites = getCallSites(3.4); - assert.strictEqual(callSites.length, 3); + assert.throws(() => { + const callSites = getCallSites(3.6); + assert.strictEqual(callSites.length, 3); + }, common.expectsError({ + code: 'ERR_OUT_OF_RANGE' + })); } {