@@ -12,75 +12,6 @@ using namespace v8;
1212using namespace tns ;
1313
1414tns::SimpleAllocator g_allocator;
15-
16- static void divide (const FunctionCallbackInfo<Value>& args) {
17- CHECK (args[0 ]->IsInt32 ());
18- CHECK (args[1 ]->IsInt32 ());
19- auto a = args[0 ].As <v8::Int32>();
20- auto b = args[1 ].As <v8::Int32>();
21-
22- if (b->Value () == 0 ) {
23- return ;
24- }
25-
26- double result = a->Value () / b->Value ();
27- args.GetReturnValue ().Set (result);
28- }
29-
30- static double FastDivide (const int32_t this_arg, const int32_t a, const int32_t b, v8::FastApiCallbackOptions& options) {
31- DEBUG_WRITE_FORCE (" %s" , " FAST" );
32- if (b == 0 ) {
33- options.fallback = true ;
34- return 0 ;
35- } else {
36- return a / b;
37- }
38- }
39-
40- CFunction fast_divide_ (CFunction::Make(FastDivide));
41-
42-
43- Local <v8::FunctionTemplate> NewFunctionTemplate (
44- v8::Isolate *isolate,
45- v8::FunctionCallback callback,
46- Local <v8::Value> data,
47- Local <v8::Signature> signature,
48- v8::ConstructorBehavior behavior,
49- v8::SideEffectType side_effect_type,
50- const v8::CFunction *c_function) {
51- return v8::FunctionTemplate::New (isolate,
52- callback,
53- data,
54- signature,
55- 0 ,
56- behavior,
57- side_effect_type,
58- c_function);
59- }
60-
61- void SetFastMethod (Isolate* isolate,
62- Local<Template> that,
63- const char * name,
64- v8::FunctionCallback slow_callback,
65- const v8::CFunction* c_function,
66- Local<v8::Value> data) {
67- Local<v8::FunctionTemplate> t =
68- NewFunctionTemplate (isolate,
69- slow_callback,
70- data,
71- Local<v8::Signature>(),
72- v8::ConstructorBehavior::kThrow ,
73- v8::SideEffectType::kHasSideEffect ,
74- c_function);
75- // kInternalized strings are created in the old space.
76- const v8::NewStringType type = v8::NewStringType::kInternalized ;
77- Local<v8::String> name_string =
78- v8::String::NewFromUtf8 (isolate, name, type).ToLocalChecked ();
79- that->Set (name_string, t);
80- }
81-
82-
83-
8415JSR::JSR (): isolate(nullptr ) {
8516 v8::Isolate::CreateParams create_params;
8617 create_params.array_buffer_allocator = &g_allocator;
@@ -139,23 +70,6 @@ napi_status js_create_napi_env(napi_env* env, napi_runtime runtime) {
13970 v8::Local<v8::Context> context = v8::Context::New (jsr->isolate );
14071 *env = new napi_env__ (context, NAPI_VERSION_EXPERIMENTAL);
14172 JSR::env_to_jsr_cache.insert (std::make_pair (*env, jsr));
142-
143- v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New (jsr->isolate , [](const v8::FunctionCallbackInfo<v8::Value>& args) {
144-
145- });
146- // Set the function on the global object
147- v8::Local<v8::Function> func = func_template->GetFunction (context).ToLocalChecked ();
148- context->Global ()->Set (context, v8::String::NewFromUtf8 (jsr->isolate , " directFunction" ).ToLocalChecked (), func).FromJust ();
149-
150-
151- v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New (jsr->isolate );
152-
153- SetFastMethod (jsr->isolate , global_template, " directFunction" , divide, &fast_divide_, v8::Local<Value>());
154-
155- // Create an instance of the ObjectTemplate
156- v8::Local<v8::Object> instance = global_template->NewInstance (context).ToLocalChecked ();
157- context->Global ()->Set (context, v8::String::NewFromUtf8 (jsr->isolate , " fastObject" ).ToLocalChecked (), instance).FromJust ();
158-
15973 return napi_ok;
16074}
16175
0 commit comments