Skip to content

Commit 2d58799

Browse files
committed
Merge branch 'master' into release
2 parents c7efe3b + 6b9b2d6 commit 2d58799

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2714
-1362
lines changed

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Android Runtime Changelog
2+
==============================
3+
4+
0.10.0 (2015, April 17)
5+
==
6+
7+
### Fixed
8+
9+
### New
10+
11+
* Added Dynamic Generator for binding proxies. This boosts the initial loading time, especially on Android 5.0+ devices.
12+
* Added several optimization techniques, which further optimize the loading time and the overall performance.
13+
* Improved the error reporting mechanism for Debug builds.
14+
* Added support for package.json and index.js for bootstrapping an application.
15+
16+
### Breaking Changes
17+
18+
* Removed the simulated property-like support for Android types. E.g. the `android.content.Intent.getAction()` previously was accessible like `android.content.Intent.Action`. This is no longer valid as it contradicts with the Android APIs.
19+
* Changed the way `extend` constructs work
20+
```javascript
21+
// WRONG
22+
var handler = new android.os.Handler.extend({...})();
23+
24+
// CORRECT
25+
var handlerType = android.os.Handler.extend({...});
26+
var handler = new handlerType();
27+
```
28+
* The directory structure in the `assets` folder has changed. The `tns_modules` directory is now within the `assets/app` one. To migrate older CLI projects to the new structure simply move the content of the inner app folder one level up:
29+
30+
####Previous structure:
31+
```
32+
|--app
33+
|--|--app
34+
|--|--|--bootstrap.js
35+
|--|--|--myFile.js
36+
|--|--tns_modules
37+
```
38+
39+
####New structure:
40+
```
41+
|--app
42+
|--|--bootstrap.js
43+
|--|--myFile.js
44+
|--|--tns_modules
45+
```

src/jni/Android.mk

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,47 @@ LOCAL_PATH := $(call my-dir)
33
include $(CLEAR_VARS)
44
LOCAL_MODULE := v8_base
55
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
6-
LOCAL_SRC_FILES := libs/arm/libv8_base.arm.a
6+
LOCAL_SRC_FILES := libs/arm/libv8_base.a
77
else ifeq ($(TARGET_ARCH_ABI),armeabi)
8-
LOCAL_SRC_FILES := libs/arm/libv8_base.arm.a
8+
LOCAL_SRC_FILES := libs/arm/libv8_base.a
99
else ifeq ($(TARGET_ARCH_ABI),x86)
10-
LOCAL_SRC_FILES := libs/x86/libv8_base.ia32.a
10+
LOCAL_SRC_FILES := libs/x86/libv8_base.a
1111
endif
1212
include $(PREBUILT_STATIC_LIBRARY)
1313

14+
include $(CLEAR_VARS)
15+
LOCAL_MODULE := v8_libplatform
16+
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
17+
LOCAL_SRC_FILES := libs/arm/libv8_libplatform.a
18+
else ifeq ($(TARGET_ARCH_ABI),armeabi)
19+
LOCAL_SRC_FILES := libs/arm/libv8_libplatform.a
20+
else ifeq ($(TARGET_ARCH_ABI),x86)
21+
LOCAL_SRC_FILES := libs/x86/libv8_libplatform.a
22+
endif
23+
include $(PREBUILT_STATIC_LIBRARY)
24+
25+
26+
include $(CLEAR_VARS)
27+
LOCAL_MODULE := v8_libbase
28+
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
29+
LOCAL_SRC_FILES := libs/arm/libv8_libbase.a
30+
else ifeq ($(TARGET_ARCH_ABI),armeabi)
31+
LOCAL_SRC_FILES := libs/arm/libv8_libbase.a
32+
else ifeq ($(TARGET_ARCH_ABI),x86)
33+
LOCAL_SRC_FILES := libs/x86/libv8_libbase.a
34+
endif
35+
include $(PREBUILT_STATIC_LIBRARY)
36+
37+
38+
1439
include $(CLEAR_VARS)
1540
LOCAL_MODULE := v8_nosnapshot
1641
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
17-
LOCAL_SRC_FILES := libs/arm/libv8_nosnapshot.arm.a
42+
LOCAL_SRC_FILES := libs/arm/libv8_nosnapshot.a
1843
else ifeq ($(TARGET_ARCH_ABI),armeabi)
19-
LOCAL_SRC_FILES := libs/arm/libv8_nosnapshot.arm.a
44+
LOCAL_SRC_FILES := libs/arm/libv8_nosnapshot.a
2045
else ifeq ($(TARGET_ARCH_ABI),x86)
21-
LOCAL_SRC_FILES := libs/x86/libv8_nosnapshot.ia32.a
46+
LOCAL_SRC_FILES := libs/x86/libv8_nosnapshot.a
2247
endif
2348
include $(PREBUILT_STATIC_LIBRARY)
2449

@@ -47,14 +72,14 @@ LOCAL_SRC_FILES := com_tns_Platform.cpp com_tns_JsDebugger.cpp com_tns_AssetExtr
4772
FieldAccessor.cpp ArrayElementAccessor.cpp \
4873
ExceptionUtil.cpp Util.cpp Logger.cpp Profiler.cpp \
4974
ObjectManager.cpp NumericCasts.cpp WeakRef.cpp \
50-
MetadataMethodInfo.cpp
75+
MetadataMethodInfo.cpp SimpleProfiler.cpp
5176
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
5277
LOCAL_LDLIBS := -llog -landroid -lz
5378
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
54-
LOCAL_STATIC_LIBRARIES := v8_base v8_nosnapshot zip android-ndk-profiler
79+
LOCAL_STATIC_LIBRARIES := v8_base v8_libbase v8_libplatform v8_nosnapshot zip android-ndk-profiler
5580
#LOCAL_CFLAGS += -pg -DNDK_PROFILER_ENABLED
5681
else
57-
LOCAL_STATIC_LIBRARIES := v8_base v8_nosnapshot zip
82+
LOCAL_STATIC_LIBRARIES := v8_base v8_libbase v8_libplatform v8_nosnapshot zip
5883
endif
5984
include $(BUILD_SHARED_LIBRARY)
6085

src/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
APP_ABI := armeabi-v7a x86
1+
APP_ABI := armeabi-v7a x86
22

33
APP_STL := stlport_static
44
#APP_STL := gnustl_static

src/jni/ArgConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ void ArgConverter::NativeScriptLongFunctionCallback(const v8::FunctionCallbackIn
5757
auto isolate = Isolate::GetCurrent();
5858
args.This()->SetHiddenValue(V8StringConstants::GetJavaLong(), Boolean::New(isolate, true));
5959
args.This()->SetHiddenValue(ConvertToV8String(V8StringConstants::MARKED_AS_LONG), args[0]);
60-
args.This()->Set(V8StringConstants::GetValue(), args[0], (PropertyAttribute)(ReadOnly | DontDelete));
60+
args.This()->Set(V8StringConstants::GetValue(), args[0]);
6161

62-
args.This()->SetPrototype(Handle<NumberObject>::New(Isolate::GetCurrent(), *NAN_NUMBER_OBJECT));
62+
args.This()->SetPrototype(Local<NumberObject>::New(Isolate::GetCurrent(), *NAN_NUMBER_OBJECT));
6363
}
6464

6565

src/jni/ExceptionUtil.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,15 @@ bool ExceptionUtil::ThrowExceptionToJava(TryCatch& tc, const string& prependMess
245245
{
246246
Isolate *isolate = Isolate::GetCurrent();
247247
auto ex = tc.Exception();
248-
string message = PrintErrorMessage(tc.Message(), ex);
248+
249+
bool isExceptionEmpty = ex.IsEmpty();
250+
bool isMessageEmpty = tc.Message().IsEmpty();
251+
252+
string message;
253+
if(!isExceptionEmpty && !isMessageEmpty){
254+
message = PrintErrorMessage(tc.Message(), ex);
255+
}
256+
249257
stringstream ss;
250258
ss << endl << prependMessage << message;
251259
string loggedMessage = ss.str();

src/jni/JEnv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ JEnv::JEnv(bool detach)
2626
}
2727

2828
JEnv::JEnv(JNIEnv *jniEnv)
29-
: m_env(jniEnv)
29+
: m_env(jniEnv), m_detach(false)
3030
{
3131
}
3232

src/jni/JsDebugger.cpp

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "JsDebugger.h"
2-
#include "v8-debug.h"
2+
#include "V8GlobalHelpers.h"
3+
#include "JniLocalRef.h"
34
#include <assert.h>
4-
#include <android/log.h>
55

66
using namespace std;
77
using namespace tns;
@@ -10,71 +10,80 @@ JsDebugger::JsDebugger()
1010
{
1111
}
1212

13-
void JsDebugger::Init(const string& packageName, int port)
13+
void JsDebugger::Init(v8::Isolate *isolate, const string& packageName)
1414
{
15+
s_isolate = isolate;
1516
s_packageName = packageName;
16-
s_port = port;
1717

1818
JEnv env;
1919
s_JsDebuggerClass = env.FindClass("com/tns/JsDebugger");
2020
assert(s_JsDebuggerClass != nullptr);
21-
s_DispatchMessagesDebugAgentCallback = env.GetStaticMethodID(s_JsDebuggerClass, "dispatchMessagesDebugAgentCallback", "()Z");
22-
assert(s_DispatchMessagesDebugAgentCallback != nullptr);
2321

24-
v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback);
22+
s_EnqueueMessage = env.GetStaticMethodID(s_JsDebuggerClass, "enqueueMessage", "(Ljava/lang/String;)V");
23+
assert(s_EnqueueMessage != nullptr);
2524
}
2625

27-
int JsDebugger::GetDebuggerPort()
26+
string JsDebugger::GetPackageName()
2827
{
29-
return s_port;
28+
return s_packageName;
3029
}
3130

32-
int JsDebugger::GetCurrentDebuggerPort()
31+
void JsDebugger::MyMessageHandler(const v8::Debug::Message& message)
3332
{
34-
__android_log_print(ANDROID_LOG_DEBUG, "TNS.Native", "GetCurrentDebuggerPort ret=%d", s_currentPort);
35-
return s_currentPort;
33+
auto json = message.GetJSON();
34+
auto str = ConvertToString(json);
35+
36+
JEnv env;
37+
JniLocalRef s(env.NewStringUTF(str.c_str()));
38+
39+
env.CallStaticVoidMethod(s_JsDebuggerClass, s_EnqueueMessage, (jstring)s);
3640
}
3741

38-
string JsDebugger::GetPackageName()
42+
void JsDebugger::Enable()
3943
{
40-
return s_packageName;
44+
auto isolate = s_isolate;
45+
v8::Isolate::Scope isolate_scope(isolate);
46+
v8::HandleScope handleScope(isolate);
47+
48+
v8::Debug::SetMessageHandler(MyMessageHandler);
4149
}
4250

43-
void JsDebugger::DispatchMessagesDebugAgentCallback()
51+
void JsDebugger::Disable()
4452
{
45-
JEnv env(true);
46-
jboolean success = env.CallStaticBooleanMethod(s_JsDebuggerClass, s_DispatchMessagesDebugAgentCallback);
47-
assert(JNI_TRUE == success);
53+
auto isolate = s_isolate;
54+
v8::Isolate::Scope isolate_scope(isolate);
55+
v8::HandleScope handleScope(isolate);
56+
57+
v8::Debug::SetMessageHandler(nullptr);
4858
}
4959

50-
void JsDebugger::ProcessDebugMessages()
60+
void JsDebugger::DebugBreak()
5161
{
52-
if (s_currentPort != INVALID_PORT)
53-
{
54-
v8::Debug::ProcessDebugMessages();
55-
}
62+
auto isolate = s_isolate;
63+
v8::Isolate::Scope isolate_scope(isolate);
64+
v8::HandleScope handleScope(isolate);
65+
66+
v8::Debug::DebugBreak(isolate);
5667
}
5768

58-
bool JsDebugger::EnableAgent(const std::string& name, int port, bool waitForConnection)
69+
void JsDebugger::ProcessDebugMessages()
5970
{
60-
bool success = ((0 < port) && (port < 65536))
61-
? v8::Debug::EnableAgent(name.c_str(), port, waitForConnection)
62-
: false;
63-
__android_log_print(ANDROID_LOG_DEBUG, "TNS.Native", "Enable V8 debugger (app=%s, port=%d, waitForConnection=%d, success=%d)", name.c_str(), port, waitForConnection, success);
64-
s_currentPort = success ? port : INVALID_PORT;
65-
return success;
71+
auto isolate = s_isolate;
72+
v8::Isolate::Scope isolate_scope(isolate);
73+
v8::HandleScope handleScope(isolate);
74+
75+
v8::Debug::ProcessDebugMessages();
6676
}
6777

68-
void JsDebugger::DisableAgent()
78+
void JsDebugger::SendCommand(uint16_t *cmd, int length)
6979
{
70-
v8::Debug::DisableAgent();
71-
s_currentPort = INVALID_PORT;
72-
__android_log_print(ANDROID_LOG_DEBUG, "TNS.Native", "Disable V8 debugger");
80+
auto isolate = s_isolate;
81+
82+
v8::Debug::SendCommand(isolate, cmd, length, nullptr);
7383
}
7484

75-
int JsDebugger::s_port = JsDebugger::INVALID_PORT;
76-
int JsDebugger::s_currentPort = JsDebugger::INVALID_PORT;
85+
v8::Isolate* JsDebugger::s_isolate = nullptr;
7786
string JsDebugger::s_packageName = "";
7887
jclass JsDebugger::s_JsDebuggerClass = nullptr;
79-
jmethodID JsDebugger::s_DispatchMessagesDebugAgentCallback = nullptr;
88+
jmethodID JsDebugger::s_EnqueueMessage = nullptr;
8089

src/jni/JsDebugger.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22
#define JSDEBUGGER_H_
33

44
#include <string>
5+
#include "v8.h"
6+
#include "v8-debug.h"
57
#include "JEnv.h"
68

79
namespace tns
810
{
911
class JsDebugger
1012
{
1113
public:
12-
static void Init(const std::string& packageName, int port);
14+
static void Init(v8::Isolate *isolate, const std::string& packageName);
1315

1416
static void ProcessDebugMessages();
1517

16-
static bool EnableAgent(const std::string& name, int port, bool waitForConnection);
18+
static void Enable();
1719

18-
static void DisableAgent();
20+
static void Disable();
1921

20-
static int GetDebuggerPort();
21-
22-
static int GetCurrentDebuggerPort();
22+
static void DebugBreak();
2323

2424
static std::string GetPackageName();
2525

26+
static void SendCommand(uint16_t *cmd, int length);
27+
2628
private:
2729
JsDebugger();
2830

29-
static void DispatchMessagesDebugAgentCallback();
31+
static void MyMessageHandler(const v8::Debug::Message& message);
3032

31-
static int s_port;
32-
static int s_currentPort;
3333
static std::string s_packageName;
3434
static jclass s_JsDebuggerClass;
35-
static jmethodID s_DispatchMessagesDebugAgentCallback;
35+
static jmethodID s_EnqueueMessage;
36+
static v8::Isolate *s_isolate;
3637

3738
static const int INVALID_PORT = -1;
3839
};

0 commit comments

Comments
 (0)