Skip to content

Commit 89891e5

Browse files
author
hideki
committed
Applied feedbacks from @pasin
1 parent c1878eb commit 89891e5

File tree

10 files changed

+147
-4
lines changed

10 files changed

+147
-4
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
115
package com.couchbase.lite.javascript;
216

317
import com.couchbase.lite.ReplicationFilter;
@@ -9,6 +23,9 @@
923
public class JavaScriptReplicationFilterCompiler implements ReplicationFilterCompiler {
1024
@Override
1125
public ReplicationFilter compileFilterFunction(String source, String language) {
12-
return new ReplicationFilterBlockRhino(source);
26+
if (language != null && language.equalsIgnoreCase("javascript")) {
27+
return new ReplicationFilterBlockRhino(source);
28+
}
29+
throw new IllegalArgumentException(language + " is not supported");
1330
}
1431
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript;
215

316
import com.couchbase.lite.Mapper;
@@ -7,15 +20,15 @@
720
public class JavaScriptViewCompiler implements ViewCompiler {
821
@Override
922
public Mapper compileMap(String source, String language) {
10-
if (language.equals("javascript")) {
23+
if (language != null && language.equalsIgnoreCase("javascript")) {
1124
return new ViewMapBlockRhino(source);
1225
}
1326
throw new IllegalArgumentException(language + " is not supported");
1427
}
1528

1629
@Override
1730
public Reducer compileReduce(String source, String language) {
18-
if (language.equals("javascript")) {
31+
if (language != null && language.equalsIgnoreCase("javascript")) {
1932
return new ViewReduceBlockRhino(source);
2033
}
2134
throw new IllegalArgumentException(language + " is not supported");

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
115
package com.couchbase.lite.javascript;
216

317
import com.couchbase.lite.ReplicationFilter;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript;
215

316
import com.couchbase.lite.Emitter;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript;
215

316
import com.couchbase.lite.Reducer;

src/main/java/com/couchbase/lite/javascript/scopes/GlobalScope.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript.scopes;
215

316
import com.couchbase.lite.util.Log;

src/main/java/com/couchbase/lite/javascript/scopes/MapGlobalScope.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript.scopes;
215

316
import com.couchbase.lite.Emitter;

src/main/java/com/couchbase/lite/javascript/scopes/ReduceGlobalScope.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript.scopes;
215

316
import com.couchbase.lite.CouchbaseLiteException;

src/main/java/com/couchbase/lite/javascript/wrapper/CustomWrapFactory.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
114
package com.couchbase.lite.javascript.wrapper;
215

316
import org.mozilla.javascript.Context;
@@ -14,7 +27,6 @@ public class CustomWrapFactory extends WrapFactory {
1427

1528
public CustomWrapFactory() {
1629
setJavaPrimitiveWrap(false);
17-
1830
}
1931

2032
@Override

src/test/java/com/couchbase/lite/ReplicationFilterTestCase.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Copyright (c) 2015 Couchbase, Inc All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
115
package com.couchbase.lite;
216

317
import com.couchbase.lite.internal.RevisionInternal;
@@ -88,4 +102,12 @@ public void testSimpleFilterWithReqFalse2() {
88102
ReplicationFilter replicationFilter = replicationFilterCompiler.compileFilterFunction("function(doc, req) {if(doc.type && doc.type == 'order' && req.abc == 1) {return true;}else{return false}}", "javascript");
89103
assertFalse(replicationFilter.filter(savedRevision, null));
90104
}
105+
public void testInvalidLanguage() {
106+
try {
107+
ReplicationFilter replicationFilter = replicationFilterCompiler.compileFilterFunction("function(doc, req) {if(doc.type && doc.type == 'order' && req.abc == 1) {return true;}else{return false}}", "C++");
108+
fail("IllegalArgumentException should be thrown");
109+
}
110+
catch (IllegalArgumentException e){
111+
}
112+
}
91113
}

0 commit comments

Comments
 (0)