forked from rogchap/v8go
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
unbound_script.cc
58 lines (46 loc) · 1.47 KB
/
unbound_script.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********** UnboundScript & ScriptCompilerCachedData **********/
#include "unbound_script.h"
#include "context-macros.h"
#include "isolate-macros.h"
namespace v8 {
class Isolate;
}
using namespace v8;
ScriptCompilerCachedData* UnboundScriptCreateCodeCache(
Isolate* iso,
UnboundScriptPtr us_ptr) {
ISOLATE_SCOPE(iso);
Local<UnboundScript> unbound_script = us_ptr->ptr.Get(iso);
ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(unbound_script);
ScriptCompilerCachedData* cd = new ScriptCompilerCachedData;
cd->ptr = cached_data;
cd->data = cached_data->data;
cd->length = cached_data->length;
cd->rejected = cached_data->rejected;
return cd;
}
void ScriptCompilerCachedDataDelete(ScriptCompilerCachedData* cached_data) {
delete cached_data->ptr;
delete cached_data;
}
// This can only run in contexts that belong to the same isolate
// the script was compiled in
RtnValue UnboundScriptRun(ContextPtr ctx, UnboundScriptPtr us_ptr) {
LOCAL_CONTEXT(ctx)
RtnValue rtn = {};
Local<UnboundScript> unbound_script = us_ptr->ptr.Get(iso);
Local<Script> script = unbound_script->BindToCurrentContext();
Local<Value> result;
if (!script->Run(local_ctx).ToLocal(&result)) {
rtn.error = ExceptionError(try_catch, iso, local_ctx);
return rtn;
}
m_value* val = new m_value;
val->id = 0;
val->iso = iso;
val->ctx = ctx;
val->ptr = Global<Value>(iso, result);
rtn.value = tracked_value(ctx, val);
return rtn;
}