You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/05 05:25:15 UTC
[1/5] couch commit: updated refs/heads/import to 68f9777
Updated Branches:
refs/heads/import cee3471cf -> 68f977782
Check for configure settings to enable cURL
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/783326a9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/783326a9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/783326a9
Branch: refs/heads/import
Commit: 783326a985e0e3f59bf67dfb05a1d5d5fd12b5da
Parents: cee3471
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 22:08:06 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 22:08:06 2014 -0600
----------------------------------------------------------------------
rebar.config.script | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/783326a9/rebar.config.script
----------------------------------------------------------------------
diff --git a/rebar.config.script b/rebar.config.script
index 8e7c8e6..88483e8 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -19,6 +19,13 @@ end,
CouchJSPath = filename:join(["priv", CouchJSName]),
Version = string:strip(os:cmd("git describe --always"), right, $\n),
+CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
+ true ->
+ {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")),
+ Result;
+ false ->
+ []
+end.
ConfigH = [
{"SM185", ""},
@@ -35,15 +42,21 @@ ConfigH = [
ConfigSrc = [["#define ", K, " ", V, $\n] || {K, V} <- ConfigH],
ok = file:write_file("priv/couch_js/config.h", ConfigSrc),
-JS_LDFLAGS = "-lmozjs185 -DWITHOUTCURL",
+{JS_CFLAGS, JS_LDFLAGS} = case lists:keyfind(with_curl, 1, CouchConfig) of
+ {with_curl, true} ->
+ {"-DHAVE_CURL ", "-DHAVE_CURL -lmozjs185 -lcurl"};
+ _ ->
+ {"", "-lmozjs185"}
+end,
+
CouchJSSrc = ["priv/couch_js/{help,http,main,utf8,util}.c"],
BaseSpecs = [
%% couchjs
- {"darwin", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", "-DXP_UNIX -I/usr/local/include/js"}, {"LDFLAGS", JS_LDFLAGS}]}]},
- {"linux", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", "-DXP_UNIX -I/usr/include/js"}, {"LDFLAGS", JS_LDFLAGS ++ " -lm"}]}]},
- {"unix", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", "-DXP_UNIX -I/usr/local/include/js}"}, {"LDFLAGS", JS_LDFLAGS ++ " -lm"}]}]},
- {"win32", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", "-DXP_WIN -I/usr/include/js"}, {"LDFLAGS", JS_LDFLAGS}]}]},
+ {"darwin", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ "-DXP_UNIX -I/usr/local/include/js"}, {"LDFLAGS", JS_LDFLAGS}]}]},
+ {"linux", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ "-DXP_UNIX -I/usr/include/js"}, {"LDFLAGS", JS_LDFLAGS ++ " -lm"}]}]},
+ {"unix", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ "-DXP_UNIX -I/usr/local/include/js}"}, {"LDFLAGS", JS_LDFLAGS ++ " -lm"}]}]},
+ {"win32", CouchJSPath, CouchJSSrc, [{env, [{"CFLAGS", JS_CFLAGS ++ "-DXP_WIN -I/usr/include/js"}, {"LDFLAGS", JS_LDFLAGS}]}]},
% ICU
{"", "priv/couch_icu_driver.so", ["priv/icu_driver/*.c"], [{env, [
{"DRV_CFLAGS", "$DRV_CFLAGS -DPIC -O2 -fno-common"},
[5/5] couch commit: updated refs/heads/import to 68f9777
Posted by da...@apache.org.
No longer use conditional imports for main.c
Dropping support for versions of SpiderMonkey other than 1.8.5 means we
don't need to bother with the conditional import.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/68f97778
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/68f97778
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/68f97778
Branch: refs/heads/import
Commit: 68f97778257cffe9ea6dc02202fec71cd25e53e0
Parents: 91ae53e
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 22:23:26 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 22:25:04 2014 -0600
----------------------------------------------------------------------
priv/couch_js/main.c | 423 +++++++++++++++++++++++++++++++++++++++++++-
priv/couch_js/sm185.c | 431 ---------------------------------------------
rebar.config.script | 2 +-
3 files changed, 418 insertions(+), 438 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/68f97778/priv/couch_js/main.c
----------------------------------------------------------------------
diff --git a/priv/couch_js/main.c b/priv/couch_js/main.c
index 209bb02..1f1bb1d 100644
--- a/priv/couch_js/main.c
+++ b/priv/couch_js/main.c
@@ -10,12 +10,423 @@
// License for the specific language governing permissions and limitations under
// the License.
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <jsapi.h>
#include "config.h"
+#include "http.h"
+#include "utf8.h"
+#include "util.h"
+
+
+#define SETUP_REQUEST(cx) \
+ JS_SetContextThread(cx); \
+ JS_BeginRequest(cx);
+#define FINISH_REQUEST(cx) \
+ JS_EndRequest(cx); \
+ JS_ClearContextThread(cx);
+
+
+static JSClass global_class = {
+ "GlobalClass",
+ JSCLASS_GLOBAL_FLAGS,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_StrictPropertyStub,
+ JS_EnumerateStub,
+ JS_ResolveStub,
+ JS_ConvertStub,
+ JS_FinalizeStub,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+
+static JSBool
+req_ctor(JSContext* cx, uintN argc, jsval* vp)
+{
+ JSBool ret;
+ JSObject* obj = JS_NewObjectForConstructor(cx, vp);
+ if(!obj) {
+ JS_ReportError(cx, "Failed to create CouchHTTP instance.\n");
+ return JS_FALSE;
+ }
+ ret = http_ctor(cx, obj);
+ JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
+ return ret;
+}
+
+
+static void
+req_dtor(JSContext* cx, JSObject* obj)
+{
+ http_dtor(cx, obj);
+}
+
+
+static JSBool
+req_open(JSContext* cx, uintN argc, jsval* vp)
+{
+ JSObject* obj = JS_THIS_OBJECT(cx, vp);
+ jsval* argv = JS_ARGV(cx, vp);
+ JSBool ret = JS_FALSE;
+
+ if(argc == 2) {
+ ret = http_open(cx, obj, argv[0], argv[1], JSVAL_FALSE);
+ } else if(argc == 3) {
+ ret = http_open(cx, obj, argv[0], argv[1], argv[2]);
+ } else {
+ JS_ReportError(cx, "Invalid call to CouchHTTP.open");
+ }
+
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return ret;
+}
+
+
+static JSBool
+req_set_hdr(JSContext* cx, uintN argc, jsval* vp)
+{
+ JSObject* obj = JS_THIS_OBJECT(cx, vp);
+ jsval* argv = JS_ARGV(cx, vp);
+ JSBool ret = JS_FALSE;
+
+ if(argc == 2) {
+ ret = http_set_hdr(cx, obj, argv[0], argv[1]);
+ } else {
+ JS_ReportError(cx, "Invalid call to CouchHTTP.set_header");
+ }
+
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return ret;
+}
+
+
+static JSBool
+req_send(JSContext* cx, uintN argc, jsval* vp)
+{
+ JSObject* obj = JS_THIS_OBJECT(cx, vp);
+ jsval* argv = JS_ARGV(cx, vp);
+ JSBool ret = JS_FALSE;
+
+ if(argc == 1) {
+ ret = http_send(cx, obj, argv[0]);
+ } else {
+ JS_ReportError(cx, "Invalid call to CouchHTTP.send");
+ }
+
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return ret;
+}
+
+
+static JSBool
+req_status(JSContext* cx, JSObject* obj, jsid pid, jsval* vp)
+{
+ int status = http_status(cx, obj);
+ if(status < 0)
+ return JS_FALSE;
+
+ JS_SET_RVAL(cx, vp, INT_TO_JSVAL(status));
+ return JS_TRUE;
+}
+
+
+static JSBool
+base_url(JSContext *cx, JSObject* obj, jsid pid, jsval* vp)
+{
+ couch_args *args = (couch_args*)JS_GetContextPrivate(cx);
+ return http_uri(cx, obj, args, &JS_RVAL(cx, vp));
+}
+
+
+static JSBool
+evalcx(JSContext *cx, uintN argc, jsval* vp)
+{
+ jsval* argv = JS_ARGV(cx, vp);
+ JSString* str;
+ JSObject* sandbox;
+ JSObject* global;
+ JSContext* subcx;
+ JSCrossCompartmentCall* call = NULL;
+ const jschar* src;
+ size_t srclen;
+ jsval rval;
+ JSBool ret = JS_FALSE;
+ char *name = NULL;
+
+ sandbox = NULL;
+ if(!JS_ConvertArguments(cx, argc, argv, "S / o", &str, &sandbox)) {
+ return JS_FALSE;
+ }
+
+ subcx = JS_NewContext(JS_GetRuntime(cx), 8L * 1024L);
+ if(!subcx) {
+ JS_ReportOutOfMemory(cx);
+ return JS_FALSE;
+ }
+
+ SETUP_REQUEST(subcx);
+
+ src = JS_GetStringCharsAndLength(cx, str, &srclen);
+
+ // Re-use the compartment associated with the main context,
+ // rather than creating a new compartment */
+ global = JS_GetGlobalObject(cx);
+ if(global == NULL) goto done;
+ call = JS_EnterCrossCompartmentCall(subcx, global);
+
+ if(!sandbox) {
+ sandbox = JS_NewGlobalObject(subcx, &global_class);
+ if(!sandbox || !JS_InitStandardClasses(subcx, sandbox)) {
+ goto done;
+ }
+ }
+
+ if(argc > 2) {
+ name = enc_string(cx, argv[2], NULL);
+ }
+
+ if(srclen == 0) {
+ JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(sandbox));
+ } else {
+ JS_EvaluateUCScript(subcx, sandbox, src, srclen, name, 1, &rval);
+ JS_SET_RVAL(cx, vp, rval);
+ }
+
+ ret = JS_TRUE;
+
+done:
+ if(name) JS_free(cx, name);
+ JS_LeaveCrossCompartmentCall(call);
+ FINISH_REQUEST(subcx);
+ JS_DestroyContext(subcx);
+ return ret;
+}
+
+
+static JSBool
+gc(JSContext* cx, uintN argc, jsval* vp)
+{
+ JS_GC(cx);
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return JS_TRUE;
+}
+
+
+static JSBool
+print(JSContext* cx, uintN argc, jsval* vp)
+{
+ jsval* argv = JS_ARGV(cx, vp);
+ couch_print(cx, argc, argv);
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return JS_TRUE;
+}
-#if defined(SM185)
-#include "sm185.c"
-#elif defined(SM180)
-#include "sm180.c"
-#else
-#include "sm170.c"
+
+static JSBool
+quit(JSContext* cx, uintN argc, jsval* vp)
+{
+ jsval* argv = JS_ARGV(cx, vp);
+ int exit_code = 0;
+ JS_ConvertArguments(cx, argc, argv, "/i", &exit_code);
+ exit(exit_code);
+}
+
+
+static JSBool
+readline(JSContext* cx, uintN argc, jsval* vp)
+{
+ JSString* line;
+
+ /* GC Occasionally */
+ JS_MaybeGC(cx);
+
+ line = couch_readline(cx, stdin);
+ if(line == NULL) return JS_FALSE;
+
+ JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(line));
+ return JS_TRUE;
+}
+
+
+static JSBool
+seal(JSContext* cx, uintN argc, jsval* vp)
+{
+ jsval* argv = JS_ARGV(cx, vp);
+ JSObject *target;
+ JSBool deep = JS_FALSE;
+ JSBool ret;
+
+ if(!JS_ConvertArguments(cx, argc, argv, "o/b", &target, &deep))
+ return JS_FALSE;
+
+ if(!target) {
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return JS_TRUE;
+ }
+
+
+ ret = deep ? JS_DeepFreezeObject(cx, target) : JS_FreezeObject(cx, target);
+ JS_SET_RVAL(cx, vp, JSVAL_VOID);
+ return ret;
+}
+
+
+JSClass CouchHTTPClass = {
+ "CouchHTTP",
+ JSCLASS_HAS_PRIVATE
+ | JSCLASS_CONSTRUCT_PROTOTYPE
+ | JSCLASS_HAS_RESERVED_SLOTS(2),
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_StrictPropertyStub,
+ JS_EnumerateStub,
+ JS_ResolveStub,
+ JS_ConvertStub,
+ req_dtor,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+
+JSPropertySpec CouchHTTPProperties[] = {
+ {"status", 0, JSPROP_READONLY, req_status, NULL},
+ {"base_url", 0, JSPROP_READONLY | JSPROP_SHARED, base_url, NULL},
+ {0, 0, 0, 0, 0}
+};
+
+
+JSFunctionSpec CouchHTTPFunctions[] = {
+ JS_FS("_open", req_open, 3, 0),
+ JS_FS("_setRequestHeader", req_set_hdr, 2, 0),
+ JS_FS("_send", req_send, 1, 0),
+ JS_FS_END
+};
+
+
+static JSFunctionSpec global_functions[] = {
+ JS_FS("evalcx", evalcx, 0, 0),
+ JS_FS("gc", gc, 0, 0),
+ JS_FS("print", print, 0, 0),
+ JS_FS("quit", quit, 0, 0),
+ JS_FS("readline", readline, 0, 0),
+ JS_FS("seal", seal, 0, 0),
+ JS_FS_END
+};
+
+
+int
+main(int argc, const char* argv[])
+{
+ JSRuntime* rt = NULL;
+ JSContext* cx = NULL;
+ JSObject* global = NULL;
+ JSCrossCompartmentCall *call = NULL;
+ JSObject* klass = NULL;
+ JSSCRIPT_TYPE script;
+ JSString* scriptsrc;
+ const jschar* schars;
+ size_t slen;
+ jsval sroot;
+ jsval result;
+ int i;
+
+ couch_args* args = couch_parse_args(argc, argv);
+
+ rt = JS_NewRuntime(64L * 1024L * 1024L);
+ if(rt == NULL)
+ return 1;
+
+ cx = JS_NewContext(rt, args->stack_size);
+ if(cx == NULL)
+ return 1;
+
+ JS_SetErrorReporter(cx, couch_error);
+ JS_ToggleOptions(cx, JSOPTION_XML);
+ JS_SetOptions(cx, JSOPTION_METHODJIT);
+#ifdef JSOPTION_TYPE_INFERENCE
+ JS_SetOptions(cx, JSOPTION_TYPE_INFERENCE);
#endif
+ JS_SetContextPrivate(cx, args);
+
+ SETUP_REQUEST(cx);
+
+ global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
+ if(global == NULL)
+ return 1;
+
+ call = JS_EnterCrossCompartmentCall(cx, global);
+
+ JS_SetGlobalObject(cx, global);
+
+ if(!JS_InitStandardClasses(cx, global))
+ return 1;
+
+ if(couch_load_funcs(cx, global, global_functions) != JS_TRUE)
+ return 1;
+
+ if(args->use_http) {
+ http_check_enabled();
+
+ klass = JS_InitClass(
+ cx, global,
+ NULL,
+ &CouchHTTPClass, req_ctor,
+ 0,
+ CouchHTTPProperties, CouchHTTPFunctions,
+ NULL, NULL
+ );
+
+ if(!klass)
+ {
+ fprintf(stderr, "Failed to initialize CouchHTTP class.\n");
+ exit(2);
+ }
+ }
+
+ for(i = 0 ; args->scripts[i] ; i++) {
+ // Convert script source to jschars.
+ scriptsrc = couch_readfile(cx, args->scripts[i]);
+ if(!scriptsrc)
+ return 1;
+
+ schars = JS_GetStringCharsAndLength(cx, scriptsrc, &slen);
+
+ // Root it so GC doesn't collect it.
+ sroot = STRING_TO_JSVAL(scriptsrc);
+ if(JS_AddValueRoot(cx, &sroot) != JS_TRUE) {
+ fprintf(stderr, "Internal root error.\n");
+ return 1;
+ }
+
+ // Compile and run
+ script = JS_CompileUCScript(cx, global, schars, slen,
+ args->scripts[i], 1);
+ if(!script) {
+ fprintf(stderr, "Failed to compile script.\n");
+ return 1;
+ }
+
+ if(JS_ExecuteScript(cx, global, script, &result) != JS_TRUE) {
+ fprintf(stderr, "Failed to execute script.\n");
+ return 1;
+ }
+
+ // Warning message if we don't remove it.
+ JS_RemoveValueRoot(cx, &sroot);
+
+ // Give the GC a chance to run.
+ JS_MaybeGC(cx);
+ }
+
+ JS_LeaveCrossCompartmentCall(call);
+ FINISH_REQUEST(cx);
+ JS_DestroyContext(cx);
+ JS_DestroyRuntime(rt);
+ JS_ShutDown();
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/68f97778/priv/couch_js/sm185.c
----------------------------------------------------------------------
diff --git a/priv/couch_js/sm185.c b/priv/couch_js/sm185.c
deleted file mode 100644
index bfee023..0000000
--- a/priv/couch_js/sm185.c
+++ /dev/null
@@ -1,431 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <jsapi.h>
-#include "http.h"
-#include "utf8.h"
-#include "util.h"
-
-
-#define SETUP_REQUEST(cx) \
- JS_SetContextThread(cx); \
- JS_BeginRequest(cx);
-#define FINISH_REQUEST(cx) \
- JS_EndRequest(cx); \
- JS_ClearContextThread(cx);
-
-
-static JSClass global_class = {
- "GlobalClass",
- JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-static JSBool
-req_ctor(JSContext* cx, uintN argc, jsval* vp)
-{
- JSBool ret;
- JSObject* obj = JS_NewObjectForConstructor(cx, vp);
- if(!obj) {
- JS_ReportError(cx, "Failed to create CouchHTTP instance.\n");
- return JS_FALSE;
- }
- ret = http_ctor(cx, obj);
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
- return ret;
-}
-
-
-static void
-req_dtor(JSContext* cx, JSObject* obj)
-{
- http_dtor(cx, obj);
-}
-
-
-static JSBool
-req_open(JSContext* cx, uintN argc, jsval* vp)
-{
- JSObject* obj = JS_THIS_OBJECT(cx, vp);
- jsval* argv = JS_ARGV(cx, vp);
- JSBool ret = JS_FALSE;
-
- if(argc == 2) {
- ret = http_open(cx, obj, argv[0], argv[1], JSVAL_FALSE);
- } else if(argc == 3) {
- ret = http_open(cx, obj, argv[0], argv[1], argv[2]);
- } else {
- JS_ReportError(cx, "Invalid call to CouchHTTP.open");
- }
-
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return ret;
-}
-
-
-static JSBool
-req_set_hdr(JSContext* cx, uintN argc, jsval* vp)
-{
- JSObject* obj = JS_THIS_OBJECT(cx, vp);
- jsval* argv = JS_ARGV(cx, vp);
- JSBool ret = JS_FALSE;
-
- if(argc == 2) {
- ret = http_set_hdr(cx, obj, argv[0], argv[1]);
- } else {
- JS_ReportError(cx, "Invalid call to CouchHTTP.set_header");
- }
-
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return ret;
-}
-
-
-static JSBool
-req_send(JSContext* cx, uintN argc, jsval* vp)
-{
- JSObject* obj = JS_THIS_OBJECT(cx, vp);
- jsval* argv = JS_ARGV(cx, vp);
- JSBool ret = JS_FALSE;
-
- if(argc == 1) {
- ret = http_send(cx, obj, argv[0]);
- } else {
- JS_ReportError(cx, "Invalid call to CouchHTTP.send");
- }
-
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return ret;
-}
-
-
-static JSBool
-req_status(JSContext* cx, JSObject* obj, jsid pid, jsval* vp)
-{
- int status = http_status(cx, obj);
- if(status < 0)
- return JS_FALSE;
-
- JS_SET_RVAL(cx, vp, INT_TO_JSVAL(status));
- return JS_TRUE;
-}
-
-
-static JSBool
-base_url(JSContext *cx, JSObject* obj, jsid pid, jsval* vp)
-{
- couch_args *args = (couch_args*)JS_GetContextPrivate(cx);
- return http_uri(cx, obj, args, &JS_RVAL(cx, vp));
-}
-
-
-static JSBool
-evalcx(JSContext *cx, uintN argc, jsval* vp)
-{
- jsval* argv = JS_ARGV(cx, vp);
- JSString* str;
- JSObject* sandbox;
- JSObject* global;
- JSContext* subcx;
- JSCrossCompartmentCall* call = NULL;
- const jschar* src;
- size_t srclen;
- jsval rval;
- JSBool ret = JS_FALSE;
- char *name = NULL;
-
- sandbox = NULL;
- if(!JS_ConvertArguments(cx, argc, argv, "S / o", &str, &sandbox)) {
- return JS_FALSE;
- }
-
- subcx = JS_NewContext(JS_GetRuntime(cx), 8L * 1024L);
- if(!subcx) {
- JS_ReportOutOfMemory(cx);
- return JS_FALSE;
- }
-
- SETUP_REQUEST(subcx);
-
- src = JS_GetStringCharsAndLength(cx, str, &srclen);
-
- // Re-use the compartment associated with the main context,
- // rather than creating a new compartment */
- global = JS_GetGlobalObject(cx);
- if(global == NULL) goto done;
- call = JS_EnterCrossCompartmentCall(subcx, global);
-
- if(!sandbox) {
- sandbox = JS_NewGlobalObject(subcx, &global_class);
- if(!sandbox || !JS_InitStandardClasses(subcx, sandbox)) {
- goto done;
- }
- }
-
- if(argc > 2) {
- name = enc_string(cx, argv[2], NULL);
- }
-
- if(srclen == 0) {
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(sandbox));
- } else {
- JS_EvaluateUCScript(subcx, sandbox, src, srclen, name, 1, &rval);
- JS_SET_RVAL(cx, vp, rval);
- }
-
- ret = JS_TRUE;
-
-done:
- if(name) JS_free(cx, name);
- JS_LeaveCrossCompartmentCall(call);
- FINISH_REQUEST(subcx);
- JS_DestroyContext(subcx);
- return ret;
-}
-
-
-static JSBool
-gc(JSContext* cx, uintN argc, jsval* vp)
-{
- JS_GC(cx);
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-
-static JSBool
-print(JSContext* cx, uintN argc, jsval* vp)
-{
- jsval* argv = JS_ARGV(cx, vp);
- couch_print(cx, argc, argv);
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-
-static JSBool
-quit(JSContext* cx, uintN argc, jsval* vp)
-{
- jsval* argv = JS_ARGV(cx, vp);
- int exit_code = 0;
- JS_ConvertArguments(cx, argc, argv, "/i", &exit_code);
- exit(exit_code);
-}
-
-
-static JSBool
-readline(JSContext* cx, uintN argc, jsval* vp)
-{
- JSString* line;
-
- /* GC Occasionally */
- JS_MaybeGC(cx);
-
- line = couch_readline(cx, stdin);
- if(line == NULL) return JS_FALSE;
-
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(line));
- return JS_TRUE;
-}
-
-
-static JSBool
-seal(JSContext* cx, uintN argc, jsval* vp)
-{
- jsval* argv = JS_ARGV(cx, vp);
- JSObject *target;
- JSBool deep = JS_FALSE;
- JSBool ret;
-
- if(!JS_ConvertArguments(cx, argc, argv, "o/b", &target, &deep))
- return JS_FALSE;
-
- if(!target) {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
- }
-
-
- ret = deep ? JS_DeepFreezeObject(cx, target) : JS_FreezeObject(cx, target);
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- return ret;
-}
-
-
-JSClass CouchHTTPClass = {
- "CouchHTTP",
- JSCLASS_HAS_PRIVATE
- | JSCLASS_CONSTRUCT_PROTOTYPE
- | JSCLASS_HAS_RESERVED_SLOTS(2),
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- req_dtor,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-JSPropertySpec CouchHTTPProperties[] = {
- {"status", 0, JSPROP_READONLY, req_status, NULL},
- {"base_url", 0, JSPROP_READONLY | JSPROP_SHARED, base_url, NULL},
- {0, 0, 0, 0, 0}
-};
-
-
-JSFunctionSpec CouchHTTPFunctions[] = {
- JS_FS("_open", req_open, 3, 0),
- JS_FS("_setRequestHeader", req_set_hdr, 2, 0),
- JS_FS("_send", req_send, 1, 0),
- JS_FS_END
-};
-
-
-static JSFunctionSpec global_functions[] = {
- JS_FS("evalcx", evalcx, 0, 0),
- JS_FS("gc", gc, 0, 0),
- JS_FS("print", print, 0, 0),
- JS_FS("quit", quit, 0, 0),
- JS_FS("readline", readline, 0, 0),
- JS_FS("seal", seal, 0, 0),
- JS_FS_END
-};
-
-
-int
-main(int argc, const char* argv[])
-{
- JSRuntime* rt = NULL;
- JSContext* cx = NULL;
- JSObject* global = NULL;
- JSCrossCompartmentCall *call = NULL;
- JSObject* klass = NULL;
- JSSCRIPT_TYPE script;
- JSString* scriptsrc;
- const jschar* schars;
- size_t slen;
- jsval sroot;
- jsval result;
- int i;
-
- couch_args* args = couch_parse_args(argc, argv);
-
- rt = JS_NewRuntime(64L * 1024L * 1024L);
- if(rt == NULL)
- return 1;
-
- cx = JS_NewContext(rt, args->stack_size);
- if(cx == NULL)
- return 1;
-
- JS_SetErrorReporter(cx, couch_error);
- JS_ToggleOptions(cx, JSOPTION_XML);
- JS_SetOptions(cx, JSOPTION_METHODJIT);
-#ifdef JSOPTION_TYPE_INFERENCE
- JS_SetOptions(cx, JSOPTION_TYPE_INFERENCE);
-#endif
- JS_SetContextPrivate(cx, args);
-
- SETUP_REQUEST(cx);
-
- global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
- if(global == NULL)
- return 1;
-
- call = JS_EnterCrossCompartmentCall(cx, global);
-
- JS_SetGlobalObject(cx, global);
-
- if(!JS_InitStandardClasses(cx, global))
- return 1;
-
- if(couch_load_funcs(cx, global, global_functions) != JS_TRUE)
- return 1;
-
- if(args->use_http) {
- http_check_enabled();
-
- klass = JS_InitClass(
- cx, global,
- NULL,
- &CouchHTTPClass, req_ctor,
- 0,
- CouchHTTPProperties, CouchHTTPFunctions,
- NULL, NULL
- );
-
- if(!klass)
- {
- fprintf(stderr, "Failed to initialize CouchHTTP class.\n");
- exit(2);
- }
- }
-
- for(i = 0 ; args->scripts[i] ; i++) {
- // Convert script source to jschars.
- scriptsrc = couch_readfile(cx, args->scripts[i]);
- if(!scriptsrc)
- return 1;
-
- schars = JS_GetStringCharsAndLength(cx, scriptsrc, &slen);
-
- // Root it so GC doesn't collect it.
- sroot = STRING_TO_JSVAL(scriptsrc);
- if(JS_AddValueRoot(cx, &sroot) != JS_TRUE) {
- fprintf(stderr, "Internal root error.\n");
- return 1;
- }
-
- // Compile and run
- script = JS_CompileUCScript(cx, global, schars, slen,
- args->scripts[i], 1);
- if(!script) {
- fprintf(stderr, "Failed to compile script.\n");
- return 1;
- }
-
- if(JS_ExecuteScript(cx, global, script, &result) != JS_TRUE) {
- fprintf(stderr, "Failed to execute script.\n");
- return 1;
- }
-
- // Warning message if we don't remove it.
- JS_RemoveValueRoot(cx, &sroot);
-
- // Give the GC a chance to run.
- JS_MaybeGC(cx);
- }
-
- JS_LeaveCrossCompartmentCall(call);
- FINISH_REQUEST(cx);
- JS_DestroyContext(cx);
- JS_DestroyRuntime(rt);
- JS_ShutDown();
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/68f97778/rebar.config.script
----------------------------------------------------------------------
diff --git a/rebar.config.script b/rebar.config.script
index 88483e8..7221d0f 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -49,7 +49,7 @@ ok = file:write_file("priv/couch_js/config.h", ConfigSrc),
{"", "-lmozjs185"}
end,
-CouchJSSrc = ["priv/couch_js/{help,http,main,utf8,util}.c"],
+CouchJSSrc = ["priv/couch_js/*.c"],
BaseSpecs = [
%% couchjs
[2/5] couch commit: updated refs/heads/import to 68f9777
Posted by da...@apache.org.
Ignore built files
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/331d549a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/331d549a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/331d549a
Branch: refs/heads/import
Commit: 331d549a48874bc44177d4a9001ba152bae5b11c
Parents: 783326a
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 22:09:10 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 22:09:10 2014 -0600
----------------------------------------------------------------------
.gitignore | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/331d549a/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e5bb133
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*.o
+*.so
+ebin/
+
+priv/couch_js/config.h
+priv/couchjs
+priv/couchspawnkillable
[3/5] couch commit: updated refs/heads/import to 68f9777
Posted by da...@apache.org.
Switch JSON encoding/decoding to Jiffy
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/bc948321
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/bc948321
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/bc948321
Branch: refs/heads/import
Commit: bc9483216b76c4bf61eb7223e0e14289420129e3
Parents: 331d549
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 22:20:32 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 22:20:32 2014 -0600
----------------------------------------------------------------------
include/couch_db.hrl | 4 ++--
src/couch_util.erl | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc948321/include/couch_db.hrl
----------------------------------------------------------------------
diff --git a/include/couch_db.hrl b/include/couch_db.hrl
index ffecae0..2c015df 100644
--- a/include/couch_db.hrl
+++ b/include/couch_db.hrl
@@ -18,8 +18,8 @@
-define(MIN_STR, <<"">>).
-define(MAX_STR, <<255>>). % illegal utf string
--define(JSON_ENCODE(V), ejson:encode(V)).
--define(JSON_DECODE(V), ejson:decode(V)).
+-define(JSON_ENCODE(V), couch_util:json_encode(V)).
+-define(JSON_DECODE(V), couch_util:json_decode(V)).
-define(b2l(V), binary_to_list(V)).
-define(l2b(V), list_to_binary(V)).
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc948321/src/couch_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_util.erl b/src/couch_util.erl
index d09211a..beb9622 100644
--- a/src/couch_util.erl
+++ b/src/couch_util.erl
@@ -21,6 +21,7 @@
-export([get_nested_json_value/2, json_user_ctx/1]).
-export([proplist_apply_field/2, json_apply_field/2]).
-export([to_binary/1, to_integer/1, to_list/1, url_encode/1]).
+-export([json_encode/1, json_decode/1]).
-export([verify/2,simple_call/2,shutdown_sync/1]).
-export([get_value/2, get_value/3]).
-export([md5/1, md5_init/0, md5_update/2, md5_final/1]).
@@ -376,6 +377,17 @@ url_encode([H|T]) ->
url_encode([]) ->
[].
+json_encode(V) ->
+ jiffy:encode(V, [force_utf8]).
+
+json_decode(V) ->
+ try
+ jiffy:decode(V)
+ catch
+ throw:Error ->
+ throw({invalid_json, Error})
+ end.
+
verify([X|RestX], [Y|RestY], Result) ->
verify(RestX, RestY, (X bxor Y) bor Result);
verify([], [], Result) ->
[4/5] couch commit: updated refs/heads/import to 68f9777
Posted by da...@apache.org.
Switch the default URI port to 15986
BigCouch has the single node API on 15986 for node 1. This is just a
temporary convenience change while we hack on the merge.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/91ae53ee
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/91ae53ee
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/91ae53ee
Branch: refs/heads/import
Commit: 91ae53eeea9dee7b8c4d788a28e9ad51072c9381
Parents: bc94832
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 22:21:02 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 22:21:02 2014 -0600
----------------------------------------------------------------------
priv/couch_js/http.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/91ae53ee/priv/couch_js/http.c
----------------------------------------------------------------------
diff --git a/priv/couch_js/http.c b/priv/couch_js/http.c
index c66b5da..767573f 100644
--- a/priv/couch_js/http.c
+++ b/priv/couch_js/http.c
@@ -358,9 +358,9 @@ http_uri(JSContext* cx, JSObject* req, couch_args* args, jsval* uri_val)
FILE* uri_fp = NULL;
JSString* uri_str;
- // Default is http://localhost:5984/ when no uri file is specified
+ // Default is http://localhost:15986/ when no uri file is specified
if (!args->uri_file) {
- uri_str = JS_InternString(cx, "http://localhost:5984/");
+ uri_str = JS_InternString(cx, "http://localhost:15986/");
*uri_val = STRING_TO_JSVAL(uri_str);
return JS_TRUE;
}