Skip to content

Commit fd32460

Browse files
author
hideki
committed
Applied synchronized to only Function.call() instead of block of codes.
1 parent a83ed6a commit fd32460

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

src/main/java/com/couchbase/lite/javascript/ReplicationFilterBlockRhino.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ public ReplicationFilterBlockRhino(String src) {
5858

5959
@Override
6060
public boolean filter(SavedRevision revision, Map<String, Object> params) {
61-
synchronized (lockFunction) {
62-
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
63-
try {
64-
ctx.setOptimizationLevel(-1);
65-
ctx.setWrapFactory(wrapFactory);
66-
Scriptable localScope = ctx.newObject(scope);
67-
localScope.setPrototype(scope);
68-
localScope.setParentScope(null);
69-
Object jsDocument = org.mozilla.javascript.Context.javaToJS(revision.getProperties(), localScope);
70-
Object jsParams = org.mozilla.javascript.Context.javaToJS(params, localScope);
61+
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
62+
try {
63+
ctx.setOptimizationLevel(-1);
64+
ctx.setWrapFactory(wrapFactory);
65+
Scriptable localScope = ctx.newObject(scope);
66+
localScope.setPrototype(scope);
67+
localScope.setParentScope(null);
68+
Object jsDocument = org.mozilla.javascript.Context.javaToJS(revision.getProperties(), localScope);
69+
Object jsParams = org.mozilla.javascript.Context.javaToJS(params, localScope);
7170

72-
try {
71+
try {
72+
synchronized (lockFunction) {
7373
Object result = filterFunction.call(ctx, localScope, null, new Object[]{jsDocument, jsParams});
7474
return ((Boolean) result).booleanValue();
75-
} catch (org.mozilla.javascript.RhinoException e) {
76-
Log.e(TAG, "Error in filterFunction.call()", e);
77-
return false;
7875
}
79-
} finally {
80-
org.mozilla.javascript.Context.exit();
76+
} catch (org.mozilla.javascript.RhinoException e) {
77+
Log.e(TAG, "Error in filterFunction.call()", e);
78+
return false;
8179
}
80+
} finally {
81+
org.mozilla.javascript.Context.exit();
8282
}
8383
}
8484
}

src/main/java/com/couchbase/lite/javascript/ViewMapBlockRhino.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,29 @@ public ViewMapBlockRhino(String src) {
5555

5656
@Override
5757
public void map(Map<String, Object> document, Emitter emitter) {
58-
synchronized (lockFunction) {
59-
mapGlobalScope.setEmitter(emitter);
58+
mapGlobalScope.setEmitter(emitter);
6059

61-
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
62-
try {
63-
ctx.setOptimizationLevel(-1);
64-
ctx.setWrapFactory(wrapFactory);
60+
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
61+
try {
62+
ctx.setOptimizationLevel(-1);
63+
ctx.setWrapFactory(wrapFactory);
6564

66-
Scriptable localScope = ctx.newObject(globalScope);
67-
localScope.setPrototype(globalScope);
68-
localScope.setParentScope(null);
65+
Scriptable localScope = ctx.newObject(globalScope);
66+
localScope.setPrototype(globalScope);
67+
localScope.setParentScope(null);
6968

70-
Object jsDocument = org.mozilla.javascript.Context.javaToJS(document, localScope);
69+
Object jsDocument = org.mozilla.javascript.Context.javaToJS(document, localScope);
7170

72-
try {
71+
try {
72+
synchronized (lockFunction) {
7373
mapFunction.call(ctx, localScope, null, new Object[]{jsDocument});
74-
} catch (org.mozilla.javascript.RhinoException e) {
75-
Log.e(TAG, "Error in calling JavaScript map function", e);
76-
return;
7774
}
78-
} finally {
79-
org.mozilla.javascript.Context.exit();
75+
} catch (org.mozilla.javascript.RhinoException e) {
76+
Log.e(TAG, "Error in calling JavaScript map function", e);
77+
return;
8078
}
79+
} finally {
80+
org.mozilla.javascript.Context.exit();
8181
}
8282
}
8383
}

src/main/java/com/couchbase/lite/javascript/ViewReduceBlockRhino.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,30 @@ public Object reduce(List<Object> keys, List<Object> values, boolean reReduce) {
7373
return nativeCount(keys, values, reReduce);
7474
case DEFAULT:
7575
default:
76-
synchronized (lockFunction) {
77-
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
78-
try {
79-
ctx.setOptimizationLevel(-1);
80-
ctx.setWrapFactory(wrapFactory);
76+
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
77+
try {
78+
ctx.setOptimizationLevel(-1);
79+
ctx.setWrapFactory(wrapFactory);
8180

82-
Scriptable localScope = ctx.newObject(globalScope);
83-
localScope.setPrototype(globalScope);
84-
localScope.setParentScope(null);
81+
Scriptable localScope = ctx.newObject(globalScope);
82+
localScope.setPrototype(globalScope);
83+
localScope.setParentScope(null);
8584

86-
Object[] args = new Object[3];
87-
args[0] = org.mozilla.javascript.Context.javaToJS(keys, localScope);
88-
args[1] = org.mozilla.javascript.Context.javaToJS(values, localScope);
89-
args[2] = org.mozilla.javascript.Context.javaToJS(reReduce, localScope);
85+
Object[] args = new Object[3];
86+
args[0] = org.mozilla.javascript.Context.javaToJS(keys, localScope);
87+
args[1] = org.mozilla.javascript.Context.javaToJS(values, localScope);
88+
args[2] = org.mozilla.javascript.Context.javaToJS(reReduce, localScope);
9089

91-
try {
90+
try {
91+
synchronized (lockFunction) {
9292
return reduceFunction.call(ctx, localScope, null, args);
93-
} catch (org.mozilla.javascript.RhinoException e) {
94-
Log.e(TAG, "Error in calling JavaScript reduce function", e);
95-
return null;
9693
}
97-
} finally {
98-
org.mozilla.javascript.Context.exit();
94+
} catch (org.mozilla.javascript.RhinoException e) {
95+
Log.e(TAG, "Error in calling JavaScript reduce function", e);
96+
return null;
9997
}
98+
} finally {
99+
org.mozilla.javascript.Context.exit();
100100
}
101101
}
102102
}

0 commit comments

Comments
 (0)