Chromium Code Reviews| Index: runtime/embedders/android/vm_glue.cc |
| =================================================================== |
| --- runtime/embedders/android/vm_glue.cc (revision 16869) |
| +++ runtime/embedders/android/vm_glue.cc (working copy) |
| @@ -36,7 +36,7 @@ |
| Dart_Handle VMGlue::CheckError(Dart_Handle handle) { |
| if (Dart_IsError(handle)) { |
| - LOGE("Unexpected Error Handle"); |
| + LOGE("Unexpected Error Handle: %s", Dart_GetError(handle)); |
| Dart_PropagateError(handle); |
| } |
| return handle; |
| @@ -63,8 +63,8 @@ |
| // Touch, Audio, etc. All builtin libraries should be handled here |
| // (or moved into a snapshot). |
| if (strcmp(url, "android_extension.dart") == 0) { |
| - Dart_Handle source = |
| - VMGlue::LoadSourceFromFile("/data/data/com.google.dartndk/app_dart/android_extension.dart"); |
| + Dart_Handle source = VMGlue::LoadSourceFromFile( |
| + "/data/data/com.google.dartndk/app_dart/android_extension.dart"); |
| Dart_Handle library = CheckError(Dart_LoadLibrary(urlHandle, source)); |
| CheckError(Dart_SetNativeResolver(library, ResolveName)); |
| return library; |
| @@ -111,7 +111,7 @@ |
| #define MAINSCRIPT "/data/data/com.google.dartndk/app_dart/main.dart" |
| const char* VM_FLAGS[] = { |
| - "--enable_type_checks", |
| + "--enable_type_checks", // TODO(gram): This should be an option! |
| "--trace_isolates", |
| "--trace_natives", |
| }; |
| @@ -152,7 +152,7 @@ |
| int length = sb.st_size; |
| LOGI("Entry file %s is %d bytes.\n", url, length); |
| - char* buffer = reinterpret_cast<char *>(malloc((length + 1) * sizeof(char))); |
| + char* buffer = new char[length+1]; |
| if (read(fd, buffer, length) < 0) { |
| LOGE("Could not read script %s.\n", url); |
| return NULL; |
| @@ -161,7 +161,7 @@ |
| fclose(file); |
| Dart_Handle contents = CheckError(Dart_NewStringFromCString(buffer)); |
| - free(buffer); |
| + delete[] buffer; |
| return contents; |
| } |
| @@ -194,13 +194,18 @@ |
| int VMGlue::CallSetup() { |
| if (!initialized_script_) { |
| initialized_script_ = true; |
| - LOGI("Invoking setup"); |
| + LOGI("Invoking setup(0,0,%d,%d)", graphics_->width(), graphics_->height()); |
| Dart_EnterIsolate(isolate_); |
| Dart_EnterScope(); |
| - Dart_Handle args[2]; |
| - args[0] = CheckError(Dart_NewInteger(graphics_->width())); |
| - args[1] = CheckError(Dart_NewInteger(graphics_->height())); |
| - int rtn = Invoke("setup", 2, args); |
| + // We pass in x, y, w, h. x and y are always zero but we include them |
| + // because for the same app running in web page with HTML canvas this |
| + // will not be true. |
|
vsm
2013/01/09 21:17:21
Don't follow. Why would x and y be non-zero for H
gram
2013/01/09 22:33:28
You're right. My browser based bubble app used the
|
| + Dart_Handle args[4]; |
| + args[0] = CheckError(Dart_NewInteger(0)); |
| + args[1] = CheckError(Dart_NewInteger(0)); |
| + args[2] = CheckError(Dart_NewInteger(graphics_->width())); |
| + args[3] = CheckError(Dart_NewInteger(graphics_->height())); |
| + int rtn = Invoke("setup", 4, args); |
| Dart_ExitScope(); |
| Dart_ExitIsolate(); |
| LOGI("Done setup"); |
| @@ -233,7 +238,7 @@ |
| args[0] = CheckError(Dart_NewInteger(pWhen)); |
| args[1] = CheckError(Dart_NewDouble(pMoveX)); |
| args[2] = CheckError(Dart_NewDouble(pMoveY)); |
| - int rtn = Invoke(pFunction, 3, args); |
| + int rtn = Invoke(pFunction, 3, args, false); |
| Dart_ExitScope(); |
| Dart_ExitIsolate(); |
| LOGI("Done %s", pFunction); |
| @@ -254,7 +259,7 @@ |
| args[2] = CheckError(Dart_NewInteger(key_code)); |
| args[3] = CheckError(Dart_NewInteger(meta_state)); |
| args[4] = CheckError(Dart_NewInteger(repeat)); |
| - int rtn = Invoke(function, 5, args); |
| + int rtn = Invoke(function, 5, args, false); |
| Dart_ExitScope(); |
| Dart_ExitIsolate(); |
| LOGI("Done %s", function); |
| @@ -263,9 +268,10 @@ |
| return -1; |
| } |
| -int VMGlue::Invoke(const char* function, int argc, Dart_Handle* args) { |
| - Dart_Handle result; |
| - |
| +int VMGlue::Invoke(const char* function, |
| + int argc, |
| + Dart_Handle* args, |
| + bool failIfNotDefined) { |
| LOGI("in invoke(%s)", function); |
| // Lookup the library of the root script. |
| @@ -275,13 +281,28 @@ |
| return ErrorExit("Unable to find root library\n"); |
| } |
| + Dart_Handle nameHandle = Dart_NewStringFromCString(function); |
| + |
| + if (!failIfNotDefined) { |
| + // TODO(gram) - this doesn't work - we need a way of seeing if |
| + // the function is defined before we call it. |
| + // Dart_Handle h = Dart_LookupVariable(library, nameHandle); |
| + // if (Dart_IsNull(h)) { |
|
vsm
2013/01/09 21:17:21
I think you want Dart_LookupFunction instead here.
gram
2013/01/09 22:33:28
I tried a few different things here, so I may have
|
| + // LOGE("%s is not defined", function); |
| + // LOGI("out invoke"); |
| + // return 0; |
| + // } |
| + } |
| // Lookup and invoke the appropriate function. |
| LOGI("invoking %s", function); |
| - result = |
| - Dart_Invoke(library, Dart_NewStringFromCString(function), argc, args); |
| + Dart_Handle result = Dart_Invoke(library, nameHandle, argc, args); |
| if (Dart_IsError(result)) { |
| - return ErrorExit("%s\n", Dart_GetError(result)); |
| + if (failIfNotDefined) { // Temp hack; see above. |
| + return ErrorExit("Invoke %s: %s\n", function, Dart_GetError(result)); |
| + } else { |
| + LOGE("Invoke %s: %s", function, Dart_GetError(result)); |
| + } |
| } |
| // TODO(vsm): I don't think we need this. |
| @@ -289,7 +310,7 @@ |
| LOGI("Entering Dart message loop"); |
| result = Dart_RunLoop(); |
| if (Dart_IsError(result)) { |
| - return ErrorExit("%s\n", Dart_GetError(result)); |
| + return ErrorExit("Dart_RunLoop: %s\n", Dart_GetError(result)); |
| } |
| LOGI("out invoke"); |