Permalink
Browse files

[html5] Merge dev into html5-feature-0.5 and fix the conflicts (#1635)

* ci

* update hello.we

* update podfile path

* update workspace

* update xcode_sdk

* update xcode_sdk

* * [jsfm] improve the coverage of api methods test

* * [jsfm] add register module test cases

* * [jsfm] add invalid version check in downgrade

* + [jsfm] add test case for App.prototype methods

* * [jsfm] add test case for updateActions

* * [jsfm] add test case for shared methods

* + [jsfm] add some test for runtime

* * [jsfm] fix eslint

* + [jsfm] add handler.js to generate callNative task handler

* * [jsfm] separate the operation of the dispatch task into a function

* * [jsfm] add default parameter for createAction

* * [jsfm] add all top level API for dom operation

* * [jsfm] adds validation when binding events

* * [jsfm] move docMap into a sole file

* * [jsfm] move common methods into operation.js

* * [jsfm] split vdom.js into different files

* * [jsfm] move element operation methods to operation.js

* + [jsfm] add legacy test

* * [jsfm] fix condition judgment bug in insertBefore & insertAfter

* * [jsfm] move event handler validation to directive bindEvents

* * [jsfm] move extend into operation

* * [jsfm] use extend() to add prototype methods

* * [jsfm] wrap IFFE and use strict mode for js bundle

* * [jsfm] add detailed comments for runtime files

* - [jsfm] remove resetClassStyle api from document prototype

* + [jsfm] add test for static

* * [jsfm] fix format for lint

* + [jsfm] add vm/compiler test

* * [jsfm] just warn when bind an invalid event handler

* * [jsfm] move browserifyRequire out of the define

* * [jsfm] move shared utils to legacy framework

* * [jsfm] add setNativeConsole and resetNativeConsole API

* * [jsfm] add setNativeTimer and resetNativeTimer API

* + [jsfm] add build script for native & runtime

* * [jsfm] bump the Node version in ci config

* * [jsfm] skip the console test

* * [jsfm] modify the runtime usage in html5 render

* + [jsfm] add test case for strict mode

* * [jsfm] freeze the prototype of build-in objects

* * [jsfm] istanbul ignore ployfills

* + [jsfm] add test case for freezePrototype

* * [jsfm] add the missing setTimeout for Android

* + [jsfm] add test for legacy app/core/static/util

* * [jsfm] use Object.defineProperty to add properties

* * [jsfm] use Object.create to extend prototype

* + [jsfm] add unit test

* * [ios] 1. fix refresh location 2. cancel playground re-checkupdate

* + [jsfm] merge examples config file

* * [ios] remove unused

* Revert "update hello.we"

This reverts commit 990d30e.

* * [ios] update playground version

* * [jsfm] merge package.json add package.json

* * [jsfm] remove the 'this' in downgrade

* * [jsfm] import promise hack before polyfill

* * [jsfm] modify the rollup build script

* - [jsfm] no need to freeze Math.prototype

* + [jsfm] fix #969, support define methods for kind of native component

* * [jsfm] v0.16.18

* * [jsfm] add node test case

* bugfix for config

bugfix for config, need to be a json.

* * [jsfm] Bump vue version.

* bug fix. retrieve sqliteDatabase fails. (#1600)

* bug fix. retrieve sqliteDatabase fails.

* reuse WXThread#secure instead of make a new one

* update

* re create table if not exists

* * [all] fix the regex of commit message

* * [jsfm] make 'global' to be a local variable
  • Loading branch information...
1 parent aff35de commit 20636471a03fa80dd9469f6e8ce80d6f87fc8c0a @Hanks10100 Hanks10100 committed with MrRaindrop Nov 14, 2016
Showing with 2,838 additions and 956 deletions.
  1. +88 −37 android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java
  2. +54 −2 android/sdk/src/main/java/com/taobao/weex/appfram/storage/WXSQLiteOpenHelper.java
  3. +2 −2 bin/commit-msg.sh
  4. +180 −0 build/build.js
  5. +1 −1 build/rollup.config.js
  6. +19 −2 build/webpack.examples.config.js
  7. +0 −48 build/webpack.examples.vue.config.js
  8. +1 −1 circle.yml
  9. +14 −12 doc/syntax/config-n-data.md
  10. +1 −3 html5/frameworks/legacy/api/methods.js
  11. +9 −0 html5/frameworks/legacy/app/ctrl/init.js
  12. +3 −1 html5/frameworks/legacy/app/ctrl/misc.js
  13. +6 −6 html5/frameworks/legacy/app/downgrade.js
  14. +6 −0 html5/frameworks/legacy/app/index.js
  15. +2 −0 html5/frameworks/legacy/core/array.js
  16. +5 −0 html5/frameworks/legacy/core/observer.js
  17. +1 −0 html5/frameworks/legacy/core/state.js
  18. +1 −0 html5/frameworks/legacy/core/watcher.js
  19. +6 −0 html5/frameworks/legacy/index.js
  20. +1 −0 html5/frameworks/legacy/static/bridge.js
  21. +2 −0 html5/frameworks/legacy/static/create.js
  22. +2 −0 html5/frameworks/legacy/static/life.js
  23. +1 −0 html5/frameworks/legacy/static/misc.js
  24. +3 −0 html5/frameworks/legacy/static/register.js
  25. +6 −2 html5/frameworks/legacy/util/index.js
  26. +1 −0 html5/{shared/utils.js → frameworks/legacy/util/shared.js}
  27. +1 −1 html5/frameworks/legacy/vm/directive.js
  28. +1 −0 html5/frameworks/legacy/vm/events.js
  29. +1 −1 html5/render/browser/base/component/valueFilter.js
  30. +4 −4 html5/render/browser/render/index.js
  31. +7 −2 html5/render/native/index.js
  32. +72 −0 html5/runtime/handler.js
  33. +0 −10 html5/runtime/helper.js
  34. +20 −1 html5/runtime/index.js
  35. +1 −1 html5/runtime/init.js
  36. +195 −90 html5/runtime/listener.js
  37. +0 −581 html5/runtime/vdom.js
  38. +28 −0 html5/runtime/vdom/comment.js
  39. +169 −0 html5/runtime/vdom/document.js
  40. +355 −0 html5/runtime/vdom/element.js
  41. +11 −0 html5/runtime/vdom/index.js
  42. +30 −0 html5/runtime/vdom/node.js
  43. +241 −0 html5/runtime/vdom/operation.js
  44. +57 −41 html5/shared/console.js
  45. +18 −0 html5/shared/freeze.js
  46. +10 −24 html5/shared/index.js
  47. +2 −4 html5/shared/promise.js
  48. +25 −16 html5/shared/setTimeout.js
  49. +2 −2 html5/test/case/basic/require.source.js
  50. +3 −1 html5/test/case/prepare.js
  51. +25 −0 html5/test/case/tester.js
  52. +17 −0 html5/test/case/throws/global-variable1.source.js
  53. +15 −0 html5/test/case/throws/global-variable2.source.js
  54. +22 −0 html5/test/case/throws/global-variable3.source.js
  55. +17 −1 html5/test/unit/default/api/methods.js
  56. +71 −0 html5/test/unit/default/app/ctrl.js
  57. +6 −0 html5/test/unit/default/app/downgrade.js
  58. +6 −0 html5/test/unit/default/app/index.js
  59. +41 −0 html5/test/unit/default/app/register.js
  60. +45 −1 html5/test/unit/default/runtime.js
  61. +7 −0 html5/test/unit/default/util/index.js
  62. +125 −0 html5/test/unit/default/util/shared.js
  63. +1 −0 html5/test/unit/default/vm/events.js
  64. +364 −0 html5/test/unit/default/vm/vm.js
  65. +183 −28 html5/test/unit/shared/console.js
  66. +24 −1 html5/test/unit/shared/index.js
  67. +0 −3 html5/test/unit/vdom/index.js
  68. +172 −1 html5/test/unit/vdom/listener.js
  69. +21 −0 html5/test/unit/vdom/node.js
  70. +0 −3 ios/playground/WeexDemo/AppDelegate.m
  71. +5 −7 ios/playground/WeexDemo/Info.plist
  72. +0 −12 ios/sdk/WeexSDK/Sources/Component/WXRefreshComponent.m
  73. +3 −3 package.json
@@ -207,9 +207,12 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteFullException;
import android.database.sqlite.SQLiteStatement;
+import android.support.annotation.Nullable;
+import com.taobao.weex.common.WXThread;
import com.taobao.weex.utils.WXLogUtils;
import java.util.ArrayList;
@@ -225,11 +228,14 @@
private ExecutorService mExecutorService;
- private void execute(Runnable runnable) {
+ private void execute(@Nullable final Runnable runnable) {
if (mExecutorService == null) {
mExecutorService = Executors.newSingleThreadExecutor();
}
- mExecutorService.execute(runnable);
+
+ if(runnable != null) {
+ mExecutorService.execute(WXThread.secure(runnable));
+ }
}
public DefaultWXStorage(Context context) {
@@ -243,7 +249,7 @@ public void setItem(final String key, final String value, final OnResultReceived
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.setItemResult(performSetItem(key, value, false, true));
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -257,7 +263,7 @@ public void getItem(final String key, final OnResultReceivedListener listener) {
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.getItemResult(performGetItem(key));
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -271,7 +277,7 @@ public void removeItem(final String key, final OnResultReceivedListener listener
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.removeItemResult(performRemoveItem(key));
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -285,7 +291,7 @@ public void length(final OnResultReceivedListener listener) {
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.getLengthResult(performGetLength());
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -299,7 +305,7 @@ public void getAllKeys(final OnResultReceivedListener listener) {
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.getAllkeysResult(performGetAllKeys());
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -313,7 +319,7 @@ public void setItemPersistent(final String key, final String value, final OnResu
@Override
public void run() {
Map<String, Object> data = StorageResultHandler.setItemResult(performSetItem(key, value, true, true));
- if(listener == null){
+ if (listener == null) {
return;
}
listener.onReceived(data);
@@ -323,15 +329,29 @@ public void run() {
@Override
public void close() {
- mDatabaseSupplier.closeDatabase();
+ try {
+ mDatabaseSupplier.closeDatabase();
+ if (mExecutorService != null) {
+ mExecutorService.shutdown();
+ mExecutorService = null;
+ }
+ } catch (Exception e) {
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, e.getMessage());
+ }
}
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
- WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE,"set k-v to storage(key:"+ key + ",value:"+ value+",isPersistent:"+isPersistent+",allowRetry:"+allowRetryWhenFull+")");
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return false;
+ }
+
+ WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
- SQLiteStatement statement = mDatabaseSupplier.getDatabase().compileStatement(sql);
+ SQLiteStatement statement = null;
String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
try {
+ statement = database.compileStatement(sql);
statement.clearBindings();
statement.bindString(1, key);
statement.bindString(2, value);
@@ -340,61 +360,74 @@ private boolean performSetItem(String key, String value, boolean isPersistent, b
statement.execute();
return true;
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
- if(e instanceof SQLiteFullException){
- if(allowRetryWhenFull && trimToSize()){
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
+ if (e instanceof SQLiteFullException) {
+ if (allowRetryWhenFull && trimToSize()) {
//try again
//setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
- WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE,"retry set k-v to storage(key:"+key+",value:"+value+")");
- return performSetItem(key,value,isPersistent,false);
+ WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
+ return performSetItem(key, value, isPersistent, false);
}
}
return false;
} finally {
- statement.close();
+ if(statement != null) {
+ statement.close();
+ }
}
}
/**
* remove 10% of total record(at most) ordered by timestamp.
* */
- private boolean trimToSize(){
+ private boolean trimToSize() {
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return false;
+ }
+
List<String> toEvict = new ArrayList<>();
int num = 0;
- Cursor c = mDatabaseSupplier.getDatabase().query(WXSQLiteOpenHelper.TABLE_STORAGE, new String[]{WXSQLiteOpenHelper.COLUMN_KEY,WXSQLiteOpenHelper.COLUMN_PERSISTENT}, null, null, null, null, WXSQLiteOpenHelper.COLUMN_TIMESTAMP+" ASC");
+
+ Cursor c = database.query(WXSQLiteOpenHelper.TABLE_STORAGE, new String[]{WXSQLiteOpenHelper.COLUMN_KEY, WXSQLiteOpenHelper.COLUMN_PERSISTENT}, null, null, null, null, WXSQLiteOpenHelper.COLUMN_TIMESTAMP + " ASC");
try {
int evictSize = c.getCount() / 10;
while (c.moveToNext()) {
String key = c.getString(c.getColumnIndex(WXSQLiteOpenHelper.COLUMN_KEY));
boolean persistent = c.getInt(c.getColumnIndex(WXSQLiteOpenHelper.COLUMN_PERSISTENT)) == 1;
- if(!persistent && key != null){
+ if (!persistent && key != null) {
num++;
toEvict.add(key);
- if(num == evictSize){
+ if (num == evictSize) {
break;
}
}
}
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute trimToSize:"+e.getMessage());
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute trimToSize:" + e.getMessage());
} finally {
c.close();
}
- if(num <= 0){
+ if (num <= 0) {
return false;
}
- for(String key : toEvict){
+ for (String key : toEvict) {
performRemoveItem(key);
}
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"remove "+ num +" items by lru");
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "remove " + num + " items by lru");
return true;
}
private String performGetItem(String key) {
- Cursor c = mDatabaseSupplier.getDatabase().query(WXSQLiteOpenHelper.TABLE_STORAGE,
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return null;
+ }
+
+ Cursor c = database.query(WXSQLiteOpenHelper.TABLE_STORAGE,
new String[]{WXSQLiteOpenHelper.COLUMN_VALUE},
WXSQLiteOpenHelper.COLUMN_KEY + "=?",
new String[]{key},
@@ -403,58 +436,76 @@ private String performGetItem(String key) {
if (c.moveToNext()) {
ContentValues values = new ContentValues();
//update timestamp
- values.put(WXSQLiteOpenHelper.COLUMN_TIMESTAMP,WXSQLiteOpenHelper.sDateFormatter.format(new Date()));
- int updateResult = mDatabaseSupplier.getDatabase().update(WXSQLiteOpenHelper.TABLE_STORAGE,values,WXSQLiteOpenHelper.COLUMN_KEY+"= ?",new String[]{key});
+ values.put(WXSQLiteOpenHelper.COLUMN_TIMESTAMP, WXSQLiteOpenHelper.sDateFormatter.format(new Date()));
+ int updateResult = mDatabaseSupplier.getDatabase().update(WXSQLiteOpenHelper.TABLE_STORAGE, values, WXSQLiteOpenHelper.COLUMN_KEY + "= ?", new String[]{key});
- WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE,"update timestamp "+ (updateResult == 1 ? "success" : "failed") + " for operation [getItem(key = "+key+")]" );
+ WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "update timestamp " + (updateResult == 1 ? "success" : "failed") + " for operation [getItem(key = " + key + ")]");
return c.getString(c.getColumnIndex(WXSQLiteOpenHelper.COLUMN_VALUE));
} else {
return null;
}
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute getItem:"+e.getMessage());
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute getItem:" + e.getMessage());
return null;
} finally {
c.close();
}
}
private boolean performRemoveItem(String key) {
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return false;
+ }
+
int count = 0;
try {
- count = mDatabaseSupplier.getDatabase().delete(WXSQLiteOpenHelper.TABLE_STORAGE,
+ count = database.delete(WXSQLiteOpenHelper.TABLE_STORAGE,
WXSQLiteOpenHelper.COLUMN_KEY + "=?",
new String[]{key});
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute removeItem:" + e.getMessage());
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute removeItem:" + e.getMessage());
return false;
}
return count == 1;
}
private long performGetLength() {
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return 0;
+ }
+
String sql = "SELECT count(" + WXSQLiteOpenHelper.COLUMN_KEY + ") FROM " + WXSQLiteOpenHelper.TABLE_STORAGE;
- SQLiteStatement statement = mDatabaseSupplier.getDatabase().compileStatement(sql);
+ SQLiteStatement statement = null;
try {
+ statement = database.compileStatement(sql);
return statement.simpleQueryForLong();
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute getLength:"+e.getMessage());
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute getLength:" + e.getMessage());
return 0;
} finally {
- statement.close();
+ if(statement != null) {
+ statement.close();
+ }
}
}
private List<String> performGetAllKeys() {
+ SQLiteDatabase database = mDatabaseSupplier.getDatabase();
+ if (database == null) {
+ return null;
+ }
+
List<String> result = new ArrayList<>();
- Cursor c = mDatabaseSupplier.getDatabase().query(WXSQLiteOpenHelper.TABLE_STORAGE, new String[]{WXSQLiteOpenHelper.COLUMN_KEY}, null, null, null, null, null);
+ Cursor c = database.query(WXSQLiteOpenHelper.TABLE_STORAGE, new String[]{WXSQLiteOpenHelper.COLUMN_KEY}, null, null, null, null, null);
try {
while (c.moveToNext()) {
result.add(c.getString(c.getColumnIndex(WXSQLiteOpenHelper.COLUMN_KEY)));
}
return result;
} catch (Exception e) {
- WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute getAllKeys:"+e.getMessage());
+ WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute getAllKeys:" + e.getMessage());
return result;
} finally {
c.close();
@@ -205,8 +205,12 @@
package com.taobao.weex.appfram.storage;
import android.content.Context;
+import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.taobao.weex.utils.WXLogUtils;
@@ -234,6 +238,7 @@
static final String COLUMN_TIMESTAMP = "timestamp";
static final String COLUMN_PERSISTENT = "persistent";
+ private static final int SLEEP_TIME_MS = 30;
private static final String STATEMENT_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_STORAGE + " ("
+ COLUMN_KEY
@@ -252,7 +257,12 @@ public WXSQLiteOpenHelper(Context context) {
this.mContext = context;
}
- public SQLiteDatabase getDatabase() {
+ /**
+ * retrieve sqlite database
+ *
+ * @return a {@link SQLiteDatabase} instance or null if retrieve fails.
+ * */
+ public @Nullable SQLiteDatabase getDatabase() {
ensureDatabase();
return mDb;
}
@@ -328,7 +338,32 @@ synchronized void ensureDatabase() {
if (mDb != null && mDb.isOpen()) {
return;
}
- mDb = getWritableDatabase();
+ // Sometimes retrieving the database fails. We do 2 retries: first without database deletion
+ // and then with deletion.
+ for (int tries = 0; tries < 2; tries++) {
+ try {
+ if (tries > 0) {
+ //delete db and recreate
+ deleteDB();
+ }
+ mDb = getWritableDatabase();
+ break;
+ } catch (SQLiteException e) {
+ e.printStackTrace();
+ }
+ // Wait before retrying.
+ try {
+ Thread.sleep(SLEEP_TIME_MS);
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ if(mDb == null){
+ return;
+ }
+
+ createTableIfNotExists(mDb);
+
mDb.setMaximumSize(mMaximumDatabaseSize);
}
@@ -351,5 +386,22 @@ public void closeDatabase() {
}
}
+ private void createTableIfNotExists(@NonNull SQLiteDatabase db) {
+ Cursor cursor = null;
+ try {
+ cursor = db.rawQuery("SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name = '"+TABLE_STORAGE+"'", null);
+ if(cursor != null && cursor.getCount() > 0) {
+ return;
+ }
+ db.execSQL(STATEMENT_CREATE_TABLE);
+ }catch (Exception e){
+ e.printStackTrace();
+ }finally {
+ if(cursor != null){
+ cursor.close();
+ }
+ }
+ }
+
}
Oops, something went wrong.

0 comments on commit 2063647

Please sign in to comment.