2018-06-09 23:34:03 -04:00
|
|
|
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
|
|
|
// All rights reserved. MIT License.
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
#include "./deno_internal.h"
|
|
|
|
#include "include/deno.h"
|
|
|
|
|
|
|
|
namespace deno {
|
|
|
|
|
2018-06-11 11:01:35 -04:00
|
|
|
#ifdef DENO_MOCK_RUNTIME
|
|
|
|
#include "natives_mock_runtime.cc"
|
|
|
|
#include "snapshot_mock_runtime.cc"
|
|
|
|
#else
|
2018-06-09 23:34:03 -04:00
|
|
|
#include "natives_deno.cc"
|
|
|
|
#include "snapshot_deno.cc"
|
2018-06-11 11:01:35 -04:00
|
|
|
#endif
|
2018-06-09 23:34:03 -04:00
|
|
|
|
2018-06-11 10:48:21 -04:00
|
|
|
Deno* NewFromSnapshot(void* data, deno_recv_cb cb) {
|
2018-06-09 23:34:03 -04:00
|
|
|
auto natives_blob = *StartupBlob_natives();
|
|
|
|
auto snapshot_blob = *StartupBlob_snapshot();
|
|
|
|
|
|
|
|
v8::V8::SetNativesDataBlob(&natives_blob);
|
|
|
|
v8::V8::SetSnapshotDataBlob(&snapshot_blob);
|
|
|
|
|
|
|
|
Deno* d = new Deno;
|
|
|
|
d->cb = cb;
|
|
|
|
d->data = data;
|
|
|
|
v8::Isolate::CreateParams params;
|
|
|
|
params.array_buffer_allocator =
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
|
|
|
params.external_references = external_references;
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(params);
|
2018-06-10 08:18:15 -04:00
|
|
|
AddIsolate(d, isolate);
|
2018-06-09 23:34:03 -04:00
|
|
|
|
2018-06-11 11:01:35 -04:00
|
|
|
v8::Locker locker(isolate);
|
2018-06-09 23:34:03 -04:00
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
{
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
auto context = v8::Context::New(isolate);
|
|
|
|
d->context.Reset(d->isolate, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace deno
|
2018-06-10 08:18:15 -04:00
|
|
|
|
|
|
|
extern "C" {
|
2018-06-11 10:48:21 -04:00
|
|
|
Deno* deno_new(void* data, deno_recv_cb cb) {
|
2018-06-10 08:18:15 -04:00
|
|
|
return deno::NewFromSnapshot(data, cb);
|
|
|
|
}
|
|
|
|
}
|