Skip to content

Commit e1dff39

Browse files
committed
build(android): add debug logging, update v8 api usage
1 parent d8cdfbb commit e1dff39

4 files changed

Lines changed: 45 additions & 26 deletions

File tree

android/runtime/v8/src/native/V8Object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
8585
Local<Value> jsEvent = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, event);
8686

8787
#ifdef TI_DEBUG
88-
v8::String::Utf8Value eventName(isolate, jsEvent);
88+
v8::String::Utf8Value eventName(V8Runtime::v8_isolate, jsEvent);
8989
LOGV(TAG, "firing event \"%s\"", *eventName);
9090
#endif
9191

android/runtime/v8/src/native/V8Runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void logV8Exception(Local<Message> msg, Local<Value> data)
188188
*String::Utf8Value(V8Runtime::v8_isolate, msg->GetScriptResourceName()),
189189
msg->GetLineNumber(context).FromMaybe(-1),
190190
*String::Utf8Value(V8Runtime::v8_isolate,
191-
msg->GetSourceLine(context).FromMaybe(-1)));
191+
msg->GetSourceLine(context).ToLocalChecked()));
192192
}
193193

194194
} // namespace titanium

android/runtime/v8/src/native/modules/ScriptsModule.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void WrappedScript::Initialize(Local<Object> target, Local<Context> context)
9292
V8Util::fatalException(isolate, tryCatch);
9393
return;
9494
}
95-
target->Set(symbol, localFunction);
95+
target->Set(context, symbol, localFunction);
9696
}
9797

9898
void WrappedScript::New(const FunctionCallbackInfo<Value>& args)
@@ -133,11 +133,11 @@ void WrappedScript::CreateContext(const FunctionCallbackInfo<Value>& args)
133133
// If a sandbox is provided initial the new context's global with it.
134134
if (args.Length() > 0) {
135135
Local<Object> sandbox = args[0].As<Object>();
136-
Local<Array> keys = sandbox->GetPropertyNames(originalContext).ToLocalChecked();
136+
Local<Array> keys = sandbox->GetPropertyNames(context).ToLocalChecked();
137137

138138
for (uint32_t i = 0; i < keys->Length(); i++) {
139-
Local<String> key = keys->Get(originalContext, i).ToLocalChecked().As<String>();
140-
Local<Value> value = sandbox->Get(originalContext, key).ToLocalChecked();
139+
Local<String> key = keys->Get(context, i).ToLocalChecked().As<String>();
140+
Local<Value> value = sandbox->Get(context, key).ToLocalChecked();
141141
if (value == sandbox) {
142142
value = global;
143143
}

android/templates/module/generated/{{ModuleIdAsIdentifier}}Bootstrap.cpp.ejs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
*
77
* Warning: This file is GENERATED, and should not be modified
88
*/
9-
#include <jni.h>
10-
#include <v8.h>
11-
12-
#include <AndroidUtil.h>
13-
#include <JNIUtil.h>
149
#include <JSException.h>
1510
#include <KrollBindings.h>
1611
#include <V8Util.h>
@@ -35,19 +30,28 @@ static void <%- className %>_getBinding(const FunctionCallbackInfo<Value>& args)
3530
return;
3631
}
3732

33+
Local<Context> context = isolate->GetCurrentContext();
34+
MaybeLocal<String> maybeBinding = args[0]->ToString(context);
35+
if (maybeBinding.IsEmpty()) {
36+
titanium::JSException::Error(isolate, "<%- className %>.getBinding requires 1 argument: binding. Received argument that could not be converted to a String");
37+
args.GetReturnValue().Set(scope.Escape(Undefined(isolate)));
38+
return;
39+
}
40+
3841
Local<Object> cache;
3942
if (bindingCache.IsEmpty()) {
4043
cache = Object::New(isolate);
4144
bindingCache.Reset(isolate, cache);
4245
} else {
4346
cache = bindingCache.Get(isolate);
4447
}
45-
46-
Local<String> binding = args[0]->ToString(isolate);
47-
48-
if (cache->Has(binding)) {
49-
args.GetReturnValue().Set(scope.Escape(cache->Get(binding)));
50-
return;
48+
Local<String> binding = maybeBinding.ToLocalChecked();
49+
if (cache->Has(context, binding).FromMaybe(false)) {
50+
MaybeLocal<Value> maybeCachedValue = cache->Get(context, binding);
51+
if (!maybeCachedValue.IsEmpty()) {
52+
args.GetReturnValue().Set(scope.Escape(maybeCachedValue.ToLocalChecked()));
53+
return;
54+
}
5155
}
5256

5357
v8::String::Utf8Value bindingValue(isolate, binding);
@@ -63,8 +67,8 @@ static void <%- className %>_getBinding(const FunctionCallbackInfo<Value>& args)
6367
}
6468

6569
Local<Object> exports = Object::New(isolate);
66-
extBinding->bind(exports, isolate->GetCurrentContext());
67-
cache->Set(binding, exports);
70+
extBinding->bind(exports, context);
71+
cache->Set(context, binding, exports);
6872

6973
args.GetReturnValue().Set(scope.Escape(exports));
7074
return;
@@ -76,15 +80,19 @@ static void <%- className %>_init(Local<Object> exports, Local<Context> context)
7680
HandleScope scope(isolate);
7781

7882
for (int i = 0; titanium::natives[i].name; ++i) {
79-
Local<String> name = String::NewFromUtf8(isolate, titanium::natives[i].name);
83+
MaybeLocal<String> maybeName = String::NewFromUtf8(isolate, titanium::natives[i].name, v8::NewStringType::kNormal);
84+
if (maybeName.IsEmpty()) {
85+
LOGE(TAG, "Couldn't generate JS String for binding name: %s, skipping setting value", *titanium::natives[i].name);
86+
continue;
87+
}
88+
8089
Local<String> source = IMMUTABLE_STRING_LITERAL_FROM_ARRAY(isolate,
8190
titanium::natives[i].source, titanium::natives[i].source_length);
82-
83-
exports->Set(name, source);
91+
exports->Set(context, maybeName.ToLocalChecked(), source);
8492
}
8593

8694
Local<FunctionTemplate> constructor = FunctionTemplate::New(isolate, <%- className %>_getBinding);
87-
exports->Set(String::NewFromUtf8(isolate, "getBinding"), constructor->GetFunction(context).ToLocalChecked());
95+
exports->Set(context, String::NewFromUtf8(isolate, "getBinding", v8::NewStringType::kNormal).ToLocalChecked(), constructor->GetFunction(context).ToLocalChecked());
8896
}
8997

9098
static void <%- className %>_dispose(Isolate* isolate)
@@ -94,11 +102,22 @@ static void <%- className %>_dispose(Isolate* isolate)
94102
return;
95103
}
96104

97-
Local<Array> propertyNames = bindingCache.Get(isolate)->GetPropertyNames();
98-
uint32_t length = propertyNames->Length();
105+
Local<Object> cache = bindingCache.Get(isolate);
106+
Local<Context> context = isolate->GetCurrentContext();
107+
MaybeLocal<Array> maybePropertyNames = cache->GetPropertyNames(context);
108+
if (maybePropertyNames.IsEmpty()) {
109+
return;
110+
}
99111

112+
Local<Array> propertyNames = maybePropertyNames.ToLocalChecked();
113+
uint32_t length = propertyNames->Length();
100114
for (uint32_t i = 0; i < length; ++i) {
101-
v8::String::Utf8Value binding(isolate, propertyNames->Get(i));
115+
MaybeLocal<Value> maybePropertyName = propertyNames->Get(context, i);
116+
if (maybePropertyName.IsEmpty()) {
117+
continue;
118+
}
119+
120+
v8::String::Utf8Value binding(isolate, maybePropertyName.ToLocalChecked());
102121
int bindingLength = binding.length();
103122

104123
titanium::bindings::BindEntry *extBinding =

0 commit comments

Comments
 (0)