Skip to content

Commit

Permalink
Revert "[TIMOB-23903] Build against V8 5.7.492.71 (#8382)"
Browse files Browse the repository at this point in the history
This reverts commit 193e13e.
  • Loading branch information
sgtcoolguy committed Jul 21, 2017
1 parent 628e433 commit ce9d703
Show file tree
Hide file tree
Showing 38 changed files with 486 additions and 735 deletions.
2 changes: 1 addition & 1 deletion android/build/libv8.properties
@@ -1,2 +1,2 @@
libv8.version=5.7.492.71
libv8.version=5.1.281.59
libv8.mode=release
Expand Up @@ -667,7 +667,9 @@ beprovided to handle the result.
</#if>

<#-- Delete java proxy reference once done making the call. -->
proxy->unreferenceJavaObject(${jobjectVar});
if (!JavaObject::useGlobalRefs) {
env->DeleteLocalRef(${jobjectVar});
}

<@Proxy.cleanupMethodArguments args=methodArgs hasInvocation=hasInvocation/>

Expand Down
Expand Up @@ -45,7 +45,7 @@ using namespace v8;
Persistent<FunctionTemplate> ${className}::proxyTemplate;
jclass ${className}::javaClass = NULL;

${className}::${className}() : titanium::Proxy()
${className}::${className}(jobject javaObject) : titanium::Proxy(javaObject)
{
}

Expand All @@ -54,26 +54,13 @@ void ${className}::bindProxy(Local<Object> exports, Local<Context> context)
Isolate* isolate = context->GetIsolate();

Local<FunctionTemplate> pt = getProxyTemplate(isolate);

v8::TryCatch tryCatch(isolate);
Local<Function> constructor;
MaybeLocal<Function> maybeConstructor = pt->GetFunction(context);
if (!maybeConstructor.ToLocal(&constructor)) {
titanium::V8Util::fatalException(isolate, tryCatch);
return;
}

Local<Function> proxyConstructor = pt->GetFunction(context).ToLocalChecked();
Local<String> nameSymbol = NEW_SYMBOL(isolate, "${proxyAttrs.name}"); // use symbol over string for efficiency
<#if isModule>
MaybeLocal<Object> maybeInstance = constructor->NewInstance(context);
Local<Object> moduleInstance;
if (!maybeInstance.ToLocal(&moduleInstance)) {
titanium::V8Util::fatalException(isolate, tryCatch);
return;
}
Local<Object> moduleInstance = proxyConstructor->NewInstance(context).ToLocalChecked();
exports->Set(nameSymbol, moduleInstance);
<#else>
exports->Set(nameSymbol, constructor);
exports->Set(nameSymbol, proxyConstructor);
</#if>
}

Expand All @@ -95,7 +82,7 @@ Local<FunctionTemplate> ${className}::getProxyTemplate(Isolate* isolate)
return proxyTemplate.Get(isolate);
}

LOGD(TAG, "${className}::getProxyTemplate()");
LOGD(TAG, "GetProxyTemplate");

<#-- Query the class for the Java proxy -->
javaClass = titanium::JNIUtil::findClass("${packageName?replace('.','/')}/${className}");
Expand All @@ -113,7 +100,9 @@ Local<FunctionTemplate> ${className}::getProxyTemplate(Isolate* isolate)

proxyTemplate.Reset(isolate, t);
t->Set(titanium::Proxy::inheritSymbol.Get(isolate),
FunctionTemplate::New(isolate, titanium::Proxy::inherit<${className}>));
FunctionTemplate::New(isolate, titanium::Proxy::inherit<${className}>)->GetFunction());

titanium::ProxyFactory::registerProxyPair(javaClass, *t);

// Method bindings --------------------------------------------------------
<@Proxy.listMethods ; isFirst, name, method, signature>
Expand Down Expand Up @@ -252,7 +241,7 @@ void ${className}::${method.apiName}(const FunctionCallbackInfo<Value>& args)
holder = holder->FindInstanceInPrototypeChain(getProxyTemplate(isolate));
}

titanium::Proxy* proxy = NativeObject::Unwrap<titanium::Proxy>(holder);
titanium::Proxy* proxy = titanium::Proxy::unwrap(holder);

<#if method.args?size &gt; 0>
<@Proxy.verifyAndConvertArguments method.args method />
Expand Down Expand Up @@ -286,7 +275,7 @@ void ${className}::getter_${name}(Local<Name> property, const PropertyCallbackIn
<@Proxy.initJNIEnv/>
<@Proxy.initMethodID className=className name=property.getMethodName signature=getSignature logOnly=false/>

titanium::Proxy* proxy = NativeObject::Unwrap<titanium::Proxy>(args.Holder());
titanium::Proxy* proxy = titanium::Proxy::unwrap(args.Holder());

if (!proxy) {
args.GetReturnValue().Set(Undefined(isolate));
Expand Down Expand Up @@ -319,7 +308,7 @@ void ${className}::setter_${name}(Local<Name> property, Local<Value> value, cons

<@Proxy.initMethodID className=className name=property.setMethodName signature=setSignature logOnly=true />

titanium::Proxy* proxy = NativeObject::Unwrap<titanium::Proxy>(args.Holder());
titanium::Proxy* proxy = titanium::Proxy::unwrap(args.Holder());
if (!proxy) {
return;
}
Expand Down Expand Up @@ -355,7 +344,7 @@ void ${className}::interceptor(Local<String> property, const v8::PropertyCallbac
<@Proxy.initJNIEnv/>
<@Proxy.initMethodID className=className name=interceptor.name signature="(Ljava/lang/String;)Ljava/lang/Object;" logOnly=false/>

titanium::Proxy* proxy = NativeObject::Unwrap<titanium::Proxy>(args.Holder());
titanium::Proxy* proxy = titanium::Proxy::unwrap(args.Holder());

if (!proxy) {
args.GetReturnValue().Set(Undefined(isolate));
Expand All @@ -372,7 +361,9 @@ void ${className}::interceptor(Local<String> property, const v8::PropertyCallbac
jstring javaProperty = titanium::TypeConverter::jsStringToJavaString(env, property);
jobject jResult = (jobject) env->CallObjectMethod(javaProxy, methodID, javaProperty);

proxy->unreferenceJavaObject(javaProxy);
if (!JavaObject::useGlobalRefs) {
env->DeleteLocalRef(javaProxy);
}
env->DeleteLocalRef(javaProperty);

if (env->ExceptionCheck()) {
Expand Down
Expand Up @@ -18,7 +18,7 @@
class ${className} : public titanium::Proxy
{
public:
explicit ${className}();
explicit ${className}(jobject javaObject);

static void bindProxy(v8::Local<v8::Object>, v8::Local<v8::Context>);
static v8::Local<v8::FunctionTemplate> getProxyTemplate(v8::Isolate*);
Expand Down
Expand Up @@ -32,6 +32,7 @@
TiC.PROPERTY_SHADOW_OFFSET,
TiC.PROPERTY_SHADOW_COLOR,
TiC.PROPERTY_SHADOW_RADIUS,
TiC.PROPERTY_INCLUDE_FONT_PADDING,
TiC.PROPERTY_LINES,
TiC.PROPERTY_MAX_LINES,
TiC.PROPERTY_LINE_SPACING,
Expand Down
Expand Up @@ -32,11 +32,13 @@
TiC.PROPERTY_DATA,
TiC.PROPERTY_ON_CREATE_WINDOW,
TiC.PROPERTY_SCALES_PAGE_TO_FIT,
TiC.PROPERTY_REQUEST_HEADERS,
TiC.PROPERTY_URL,
TiC.PROPERTY_WEBVIEW_IGNORE_SSL_ERROR,
TiC.PROPERTY_OVER_SCROLL_MODE,
TiC.PROPERTY_CACHE_MODE,
TiC.PROPERTY_LIGHT_TOUCH_ENABLED
TiC.PROPERTY_LIGHT_TOUCH_ENABLED,
TiC.PROPERTY_HTML
})
public class WebViewProxy extends ViewProxy
implements Handler.Callback, OnLifecycleEvent, interceptOnBackPressedEvent
Expand Down
2 changes: 1 addition & 1 deletion android/notes.md
Expand Up @@ -10,7 +10,7 @@ TODOs!!!
=====
- Clean up all the debug logging I put in place
- Write up notes on generating debug build of library, using ndk-stack to get line numbers in native crash stack traces
- $ANDROID_SDK/adb logcat | $ANDROID_NDK/ndk-stack -sym ~/repos/titanium_mobile/android/runtime/v8/obj/local/x86
- ./adb logcat | /Users/cwilliams/Developer/SDKs/android-ndk-r10c/ndk-stack -sym /Users/cwilliams/repos/titanium_mobile/android/runtime/v8/obj/local/x86
- Use ToSomething(Context) in place of ToSomething(Isolate)
- Convert to using all of the MaybeLocal<T> APIs
- Look for other deprecated API usage and update
Expand Down
1 change: 1 addition & 0 deletions android/runtime/v8/Application.mk
Expand Up @@ -16,6 +16,7 @@ else
APP_ABI := armeabi-v7a
endif


TARGET_DEVICE := device
APP_OPTIM := release
TI_DEBUG := 1
Expand Up @@ -43,7 +43,7 @@ public final class JSDebugger

// The handshake message
// FIXME Grab the v8 version from the system!
private static final String HANDSHAKE_MESSAGE = "Type: connect\r\nV8-Version: 5.7.492.71\r\nProtocol-Version: 1\r\nEmbedding-Host: Titanium v%s\r\nContent-Length: 0\r\n\r\n";
private static final String HANDSHAKE_MESSAGE = "Type: connect\r\nV8-Version: 5.1.281.59\r\nProtocol-Version: 1\r\nEmbedding-Host: Titanium v%s\r\nContent-Length: 0\r\n\r\n";

// The port to listen to for debugger connections
private final int port;
Expand Down
@@ -1,107 +1,65 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2016-2017 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package org.appcelerator.kroll.runtime.v8;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import org.appcelerator.kroll.KrollProxySupport;
import org.appcelerator.kroll.KrollObject;
import org.appcelerator.kroll.common.Log;

public final class ReferenceTable
{
private static String TAG = "ReferenceTable";

/**
* A simple Map used to hold strong/weak reference to the Java objects we have
* paired/wrapped in native titanium::Proxy/JavaObject instances.
*/
private static HashMap<Long, Object> references = new HashMap<Long, Object>();
private static HashMap<Integer, Object> references = new HashMap<Integer, Object>();
private static int lastKey = 1;

/**
* Incrementing key, used to generate new keys when a new strong reference is
* created.
* FIXME Handle "wrapping" the value around to Long.MIN_VALUE when
* Long.MAX_VALUE is reached? What if we ever reach back up to 0 - we need to skip it!
*/
private static long lastKey = 1;

/**
* Creates a new strong reference. Done when attaching a native Proxy to a
* Java object.
/*
* Creates a new reference.
* @param object the object to reference and retain
* @return an unique key for this reference
*/
public static long createReference(Object object)
public static int createReference(Object object)
{
long key = lastKey++;
Log.d(TAG, "Creating strong reference for key: " + key, Log.DEBUG_MODE);
int key = lastKey++;
references.put(key, object);
return key;
}

/**
* Destroy the reference in our map. Done when we're deleting the native proxy.
/*
* Destroy the reference.
* @param key the key for the reference to destroy.
*/
public static void destroyReference(long key)
public static void destroyReference(int key)
{
Log.d(TAG, "Destroying reference under key: " + key, Log.DEBUG_MODE);
Object obj = references.remove(key);
if (obj instanceof WeakReference) {
obj = ((WeakReference<?>)obj).get();
}
// If it's an V8Object, set the ptr to 0, because the proxy is dead on C++ side
// This *should* prevent the native code from trying to reconstruct the proxy for any reason
if (obj instanceof KrollProxySupport) {
KrollProxySupport proxy = (KrollProxySupport) obj;
KrollObject ko = proxy.getKrollObject();
if (ko instanceof V8Object) {
V8Object v8 = (V8Object) ko;
v8.setPointer(0);
}
}
references.remove(key);
}

/**
/*
* Makes the reference "weak" which allows it to be
* collected if no other references remain.
* @param key the key for the reference to weaken.
*/
public static void makeWeakReference(long key)
public static void makeWeakReference(int key)
{
Log.d(TAG, "Downgrading to weak reference for key: " + key, Log.DEBUG_MODE);
Object ref = references.get(key);
references.put(key, new WeakReference<Object>(ref));
}

/**
/*
* Make the reference strong again to prevent future collection.
* This method will return null if the weak reference was
* invalidated and the object collected.
* @param key the key for the reference.
* @return the referenced object if the reference is still valid.
*/
public static Object clearWeakReference(long key)
public static Object clearWeakReference(int key)
{
Log.d(TAG, "Upgrading weak reference to strong for key: " + key, Log.DEBUG_MODE);
Object ref = getReference(key);
references.put(key, ref);
return ref;
}

/**
* Returns the referenced object if it's still 'alive'. It may have been a
* WeakReference that has been GC'd, in which case we'd return null.
/*
* Returns the referenced object.
* @param key the key of the reference.
* @return the object if the reference is still valid, otherwise null.
* @return the object if the reference is still valid otherwise null.
*/
public static Object getReference(long key)
public static Object getReference(int key)
{
Object ref = references.get(key);
if (ref instanceof WeakReference) {
Expand Down
Expand Up @@ -104,10 +104,11 @@ protected void finalize() throws Throwable

// JNI method prototypes
protected static native void nativeInitObject(Class<?> proxyClass, Object proxyObject);
private static native Object nativeCallProperty(long ptr, String propertyName, Object[] args);
private static native boolean nativeRelease(long ptr);

private native Object nativeCallProperty(long ptr, String propertyName, Object[] args);
private native void nativeSetProperty(long ptr, String name, Object value);
private native boolean nativeFireEvent(long ptr, Object source, long sourcePtr, String event, Object data, boolean bubble, boolean reportSuccess, int code, String errorMessage);
private native void nativeSetWindow(long ptr, Object windowProxyObject);
}

7 changes: 7 additions & 0 deletions android/runtime/v8/src/native/EventEmitter.cpp
Expand Up @@ -6,8 +6,15 @@
*
* Original code Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
*/
#include <jni.h>
#include <v8.h>

#include "AndroidUtil.h"
#include "EventEmitter.h"
#include "TypeConverter.h"
#include "V8Util.h"
#include "JNIUtil.h"
#include "V8Runtime.h"

#define TAG "EventEmitter"

Expand Down
1 change: 1 addition & 0 deletions android/runtime/v8/src/native/EventEmitter.h
Expand Up @@ -9,6 +9,7 @@
#ifndef EVENT_EMITTER_H
#define EVENT_EMITTER_H

#include <jni.h>
#include <v8.h>

#include "NativeObject.h"
Expand Down

0 comments on commit ce9d703

Please sign in to comment.