1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

deno.cc clean up

This commit is contained in:
Ryan Dahl 2018-06-10 03:44:56 +02:00
parent 092ec21381
commit 7c71785981
2 changed files with 14 additions and 32 deletions

View file

@ -34,6 +34,18 @@ IN THE SOFTWARE.
namespace deno { namespace deno {
// deno_s = Wrapped Isolate.
struct deno_s {
v8::Isolate* isolate;
std::string last_exception;
v8::Persistent<v8::Function> recv;
v8::Persistent<v8::Context> context;
RecvCallback cb;
void* data;
};
void deno_add_isolate(Deno* d, v8::Isolate* isolate);
// Extracts a C string from a v8::V8 Utf8Value. // Extracts a C string from a v8::V8 Utf8Value.
const char* ToCString(const v8::String::Utf8Value& value) { const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>"; return *value ? *value : "<string conversion failed>";
@ -249,18 +261,6 @@ void v8_init() {
v8::V8::Initialize(); v8::V8::Initialize();
} }
Deno* deno_new(void* data, RecvCallback cb) {
Deno* d = new Deno;
d->cb = cb;
d->data = data;
v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* isolate = v8::Isolate::New(params);
deno_add_isolate(d, isolate);
return d;
}
Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb) { Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb) {
Deno* d = new Deno; Deno* d = new Deno;
d->cb = cb; d->cb = cb;
@ -295,15 +295,6 @@ void deno_add_isolate(Deno* d, v8::Isolate* isolate) {
d->isolate->SetData(0, d); d->isolate->SetData(0, d);
} }
v8::StartupData SerializeInternalField(v8::Local<v8::Object> holder, int index,
void* data) {
printf("SerializeInternalField %d\n", index);
v8::StartupData sd;
sd.data = "a";
sd.raw_size = 1;
return sd;
}
v8::StartupData deno_make_snapshot(const char* js_filename, v8::StartupData deno_make_snapshot(const char* js_filename,
const char* js_source) { const char* js_source) {
auto creator = new v8::SnapshotCreator(external_references); auto creator = new v8::SnapshotCreator(external_references);

View file

@ -14,32 +14,23 @@ struct buf_s {
size_t len; size_t len;
}; };
typedef struct buf_s DenoBuf; typedef struct buf_s DenoBuf;
// Deno = Wrapped Isolate.
struct deno_s; struct deno_s;
typedef struct deno_s Deno; typedef struct deno_s Deno;
// The callback from V8 when data is sent. // The callback from V8 when data is sent.
typedef DenoBuf (*RecvCallback)(Deno* d, DenoBuf buf); typedef DenoBuf (*RecvCallback)(Deno* d, DenoBuf buf);
struct deno_s {
v8::Isolate* isolate;
std::string last_exception;
v8::Persistent<v8::Function> recv;
v8::Persistent<v8::Context> context;
RecvCallback cb;
void* data;
};
void v8_init(); void v8_init();
const char* v8_version(); const char* v8_version();
void v8_set_flags(int* argc, char** argv); void v8_set_flags(int* argc, char** argv);
// Constructors: // Constructors:
Deno* deno_new(void* data, RecvCallback cb);
Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb); Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb);
v8::StartupData deno_make_snapshot(const char* js_filename, v8::StartupData deno_make_snapshot(const char* js_filename,
const char* js_source); const char* js_source);
void deno_add_isolate(Deno* d, v8::Isolate* isolate);
void* deno_get_data(); void* deno_get_data();
// Returns nonzero on error. // Returns nonzero on error.