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
9098static 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