Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const {
validateString,
validateOneOf,
validateObject,
validateInteger,
} = require('internal/validators');
const {
isReadableStream,
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class JSGraph : public EmbedderGraph {
}

Node* V8Node(const Local<v8::Value>& value) override {
return V8Node(value.As<v8::Data>());
return V8Node(v8::Local<v8::Data>(value));
}

Node* AddNode(std::unique_ptr<Node> node) override {
Expand Down
3 changes: 2 additions & 1 deletion src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "quic/guard.h"
#include "simdutf.h"
#include "util-inl.h"
#include "v8-value.h"

namespace node {
namespace builtins {
Expand Down Expand Up @@ -441,7 +442,7 @@ void BuiltinLoader::SaveCodeCache(const std::string& id, Local<Data> data) {
new_cached_data.reset(
ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript()));
} else {
Local<Function> fun = data.As<Function>();
Local<Function> fun = data.As<Value>().As<Function>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When V8_ENABLE_CHECKS is enabled, Local::As() fails because v8::Function only supports Cast(Value*), causing a compile error.
https://github.com/nodejs/node/blob/main/deps/v8/include/v8-local-handle.h#L424.

new_cached_data.reset(ScriptCompiler::CreateCodeCacheForFunction(fun));
}
CHECK_NOT_NULL(new_cached_data);
Expand Down
2 changes: 1 addition & 1 deletion src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& 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<Uint32>()->Value();
CHECK(frames >= 1 && frames <= 200);

Expand Down
8 changes: 7 additions & 1 deletion src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmath>
Expand Down Expand Up @@ -678,10 +679,15 @@ T FromV8Value(v8::Local<v8::Value> value) {
"Type is out of unsigned integer range");
if constexpr (!loose) {
CHECK(value->IsUint32());
return static_cast<T>(value.As<v8::Uint32>()->Value());
} else {
CHECK(value->IsNumber());
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Maybe<uint32_t> maybe = value->Uint32Value(context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in line 684 why don't you just check for IsUint32?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need to accept signed values for some call sites (e.g. fs.chown), not only strict Uint32.

CHECK(!maybe.IsNothing());
return static_cast<T>(maybe.FromJust());
}
return static_cast<T>(value.As<v8::Uint32>()->Value());
} else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
static_assert(
std::numeric_limits<T>::max() <= std::numeric_limits<int32_t>::max() &&
Expand Down
15 changes: 7 additions & 8 deletions test/parallel/test-util-getcallsites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}));
}

{
Expand Down
Loading