diff --git a/src/env-inl.h b/src/env-inl.h index b32f3ee63d9b21..33c7868e247c7d 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -883,9 +883,7 @@ inline void Environment::SetMethod(v8::Local that, v8::Local context = isolate()->GetCurrentContext(); v8::Local function = NewFunctionTemplate(callback, v8::Local(), - // TODO(TimothyGu): Investigate if SetMethod is ever - // used for constructors. - v8::ConstructorBehavior::kAllow, + v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect) ->GetFunction(context) .ToLocalChecked(); @@ -903,9 +901,7 @@ inline void Environment::SetMethodNoSideEffect(v8::Local that, v8::Local context = isolate()->GetCurrentContext(); v8::Local function = NewFunctionTemplate(callback, v8::Local(), - // TODO(TimothyGu): Investigate if SetMethod is ever - // used for constructors. - v8::ConstructorBehavior::kAllow, + v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasNoSideEffect) ->GetFunction(context) .ToLocalChecked(); diff --git a/test/parallel/test-process-chdir.js b/test/parallel/test-process-chdir.js index e66d366fb7874f..005e17fac25a90 100644 --- a/test/parallel/test-process-chdir.js +++ b/test/parallel/test-process-chdir.js @@ -42,3 +42,8 @@ const err = { }; common.expectsError(function() { process.chdir({}); }, err); common.expectsError(function() { process.chdir(); }, err); + +// Check that our built-in methods do not have a prototype/constructor behaviour +// if they don't need to. This could be tested for any of our C++ methods. +assert.strictEqual(process.cwd.prototype, undefined); +assert.throws(() => new process.cwd(), TypeError);