MCPcopy Create free account
hub / github.com/Snapchat/Valdi / V8JavaScriptContext

Method V8JavaScriptContext

valdi/src/valdi/v8/V8JavaScriptContext.cpp:161–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161V8JavaScriptContext::V8JavaScriptContext(JavaScriptTaskScheduler* taskScheduler) : IJavaScriptContext(taskScheduler) {
162 initializeV8Engine();
163 _allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
164 _params.array_buffer_allocator = _allocator;
165 _isolate = v8::Isolate::New(_params);
166
167 SC_ASSERT(_isolate->GetNumberOfDataSlots() >= 1);
168
169 // NOTE(rjaber): An isolate is a VM instance with its own heap.
170 v8::HandleScope handleScope(_isolate);
171 auto ctx = v8::Context::New(_isolate);
172 ctx->Enter();
173 _context.Reset(_isolate, ctx);
174
175 auto valdiObjectTemplate = v8::ObjectTemplate::New(_isolate);
176 valdiObjectTemplate->SetInternalFieldCount(static_cast<int>(InternalFieldSlot::Count));
177 _valdiObjectTemplate.Reset(_isolate, valdiObjectTemplate);
178 auto propertyString = v8::String::NewFromUtf8Literal(_isolate, "com.snapinc.valdi.js.v8.function.private_prop");
179 auto functionPrivate = v8::Private::New(_isolate, propertyString);
180 _functionDataProperty.Reset(_isolate, functionPrivate);
181}
182
183V8JavaScriptContext::~V8JavaScriptContext() {
184 prepareForTeardown();

Callers

nothing calls this directly

Calls 5

initializeV8EngineFunction · 0.85
GetNumberOfDataSlotsMethod · 0.80
EnterMethod · 0.80
NewFunction · 0.50
ResetMethod · 0.45

Tested by

no test coverage detected