diff options
author | 2023-05-19 11:11:56 -0700 | |
---|---|---|
committer | 2023-05-19 11:18:11 -0700 | |
commit | f910d791f9ba3f573b4480853dc6b65b57055807 (patch) | |
tree | 7ae230540d9f526db0fc3e4f416c781e41c1718f /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | d6223c7f739c8159f785edae250c13b0f041ab76 (diff) | |
download | bun-f910d791f9ba3f573b4480853dc6b65b57055807.tar.gz bun-f910d791f9ba3f573b4480853dc6b65b57055807.tar.zst bun-f910d791f9ba3f573b4480853dc6b65b57055807.zip |
[node:vm] Make `vm.runInThisContext` 10x faster
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 84cef9452..433130d8d 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1306,6 +1306,13 @@ JSC: obj->putDirect( vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "isContext"_s)), JSC::JSFunction::create(vm, globalObject, 0, "isContext"_s, vmModule_isContext, ImplementationVisibility::Public), 0); + obj->putDirect( + vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "runInNewContext"_s)), + JSC::JSFunction::create(vm, globalObject, 0, "runInNewContext"_s, vmModuleRunInNewContext, ImplementationVisibility::Public), 0); + + obj->putDirect( + vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "runInThisContext"_s)), + JSC::JSFunction::create(vm, globalObject, 0, "runInThisContext"_s, vmModuleRunInThisContext, ImplementationVisibility::Public), 0); return JSValue::encode(obj); } @@ -2661,6 +2668,20 @@ void GlobalObject::finishCreation(VM& vm) this->initGeneratedLazyClasses(); + m_cachedGlobalObjectStructure.initLater( + [](const JSC::LazyProperty<JSC::JSGlobalObject, Structure>::Initializer& init) { + auto& global = *reinterpret_cast<Zig::GlobalObject*>(init.owner); + + init.set( + JSC::JSGlobalObject::createStructure(init.vm, JSC::jsNull())); + }); + + m_cachedGlobalProxyStructure.initLater( + [](const JSC::LazyProperty<JSC::JSGlobalObject, Structure>::Initializer& init) { + init.set( + JSC::JSGlobalProxy::createStructure(init.vm, init.owner, JSC::jsNull())); + }); + m_subtleCryptoObject.initLater( [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) { auto& global = *reinterpret_cast<Zig::GlobalObject*>(init.owner); @@ -3735,6 +3756,9 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_vmModuleContextMap.visit(visitor); thisObject->m_bunSleepThenCallback.visit(visitor); + thisObject->m_cachedGlobalObjectStructure.visit(visitor); + thisObject->m_cachedGlobalProxyStructure.visit(visitor); + for (auto& barrier : thisObject->m_thenables) { visitor.append(barrier); } |