Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
58946131c6 test: add process prototype node test 2025-05-29 22:32:36 -07:00
2 changed files with 28 additions and 1 deletions

View File

@@ -3143,8 +3143,20 @@ void GlobalObject::finishCreation(VM& vm)
[](const JSC::LazyProperty<JSC::JSGlobalObject, Bun::Process>::Initializer& init) {
auto* globalObject = defaultGlobalObject(init.owner);
// Create an EventEmitter instance to serve as the prototype of the
// process object. The prototype itself should be an instance of
// EventEmitter, matching Node.js behaviour.
auto emitter = WebCore::EventEmitter::create(*globalObject->scriptExecutionContext());
auto* protoStructure = WebCore::JSEventEmitter::createStructure(
init.vm,
init.owner,
WebCore::JSEventEmitter::prototype(init.vm, *globalObject));
protoStructure->setMayBePrototype(true);
auto* prototype = WebCore::JSEventEmitter::create(protoStructure, *globalObject, WTFMove(emitter));
auto* process = Bun::Process::create(
*globalObject, Bun::Process::createStructure(init.vm, init.owner, WebCore::JSEventEmitter::prototype(init.vm, *globalObject)));
*globalObject,
Bun::Process::createStructure(init.vm, init.owner, prototype));
init.set(process);
});

View File

@@ -0,0 +1,15 @@
require('../common');
const assert = require('assert');
const EventEmitter = require('events');
const proto = Object.getPrototypeOf(process);
assert(process instanceof process.constructor);
assert(proto instanceof EventEmitter);
const desc = Object.getOwnPropertyDescriptor(proto, 'constructor');
assert.strictEqual(desc.value, process.constructor);
assert.strictEqual(desc.writable, true);
assert.strictEqual(desc.enumerable, false);
assert.strictEqual(desc.configurable, true);