Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Towards windows support

This was mostly about changing the the c files to be c89 compliant.
  • Loading branch information...
commit 8cecf41d0aa3bbe3b476d9e0fb07fd273cfbc269 1 parent ae92afe
@piscisaureus piscisaureus authored
View
21 .gitignore
@@ -1,4 +1,19 @@
-/out
-/deps
-*Makefile
+*.a
+*.Makefile
*.mk
+*.o
+*.opensdf
+*.sdf
+*.sln
+*.suo
+*.vcxproj
+*.vcxproj.filters
+*.vcxproj.user
+/build/gyp
+/Debug
+/deps
+/gyp-mac-tool
+/ipch
+/Makefile
+/out
+/Release
View
9 src/luv.c
@@ -64,12 +64,11 @@ static JSBool luv_get_total_memory(JSContext *cx, unsigned argc, jsval *vp) {
static JSBool luv_loadavg(JSContext *cx, unsigned argc, jsval *vp) {
double avg[3];
+ jsval values[3];
uv_loadavg(avg);
- jsval values[] = {
- DOUBLE_TO_JSVAL(avg[0]),
- DOUBLE_TO_JSVAL(avg[1]),
- DOUBLE_TO_JSVAL(avg[2])
- };
+ values[0] = DOUBLE_TO_JSVAL(avg[0]);
+ values[1] = DOUBLE_TO_JSVAL(avg[1]),
+ values[2] = DOUBLE_TO_JSVAL(avg[2]);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(JS_NewArrayObject(cx, 3, values)));
return JS_TRUE;
}
View
8 src/luv_handle.c
@@ -27,9 +27,10 @@ void luv_on_close(uv_handle_t* handle) {
static JSBool luv_close(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_handle_t* handle;
+ JSObject* callback;
+
handle = (uv_handle_t*)JS_GetPrivate(this);
- JSObject* callback;
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &callback)) {
return JS_FALSE;
}
@@ -49,15 +50,16 @@ static JSFunctionSpec Handle_methods[] = {
int luv_handle_init(JSContext* cx, JSObject *uv) {
Handle_prototype = JS_InitClass(cx, uv, NULL,
- &Handle_class, Handle_constructor, 0,
+ &Handle_class, Handle_constructor, 0,
NULL, Handle_methods, NULL, NULL);
return 0;
}
/* Store an async callback in an object and put the object in the gc root for safekeeping */
JSBool luv_store_callback(JSContext* cx, JSObject *this, const char* name, JSObject* callback) {
+ jsval callback_val;
if (!JS_AddObjectRoot(cx, &this)) return JS_FALSE;
- jsval callback_val = OBJECT_TO_JSVAL(callback);
+ callback_val = OBJECT_TO_JSVAL(callback);
return JS_SetProperty(cx, this, name, &callback_val);
}
View
40 src/luv_stream.c
@@ -28,10 +28,11 @@ static void luv_on_connection(uv_stream_t* server, int status) {
static JSBool luv_listen(JSContext* cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_stream_t* stream;
- stream = (uv_stream_t*)JS_GetPrivate(this);
-
int backlog;
JSObject* callback;
+
+ stream = (uv_stream_t*)JS_GetPrivate(this);
+
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "io", &backlog, &callback)) {
return JS_FALSE;
}
@@ -48,9 +49,10 @@ static JSBool luv_accept(JSContext* cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_stream_t* server;
uv_stream_t* client;
+ JSObject* obj;
+
server = (uv_stream_t*)JS_GetPrivate(this);
- JSObject* obj;
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &obj)) {
return JS_FALSE;
}
@@ -74,9 +76,9 @@ static void luv_on_read(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
ref = (luv_ref_t*)stream->data;
if (nread >= 0) {
- jsval chunk[1] = { STRING_TO_JSVAL(JS_NewStringCopyN(ref->cx, buf.base, nread)) };
+ jsval chunk = STRING_TO_JSVAL(JS_NewStringCopyN(ref->cx, buf.base, nread));
- if (!luv_call_callback(ref->cx, ref->obj, "onData", 1, chunk)) {
+ if (!luv_call_callback(ref->cx, ref->obj, "onData", 1, &chunk)) {
/* TODO: report properly */
printf("Error in onData callback\n");
}
@@ -128,16 +130,19 @@ static JSBool luv_read_stop(JSContext* cx, unsigned argc, jsval* vp) {
static void luv_on_write(uv_write_t* req, int status) {
luv_ref_t* ref;
+ JSContext* cx;
+ JSObject* this;
+ JSObject* callback;
/* Get the context, instance, and handle */
ref = (luv_ref_t*)req->handle->data;
- JSContext* cx = ref->cx;
- JSObject* this = ref->obj;
+ cx = ref->cx;
+ this = ref->obj;
/* Get the callback */
ref = (luv_ref_t*)req->data;
assert(ref->cx == cx);
- JSObject* callback = ref->obj;
+ callback = ref->obj;
free(ref);
if (JS_ObjectIsFunction(cx, callback)) {
@@ -155,22 +160,27 @@ static void luv_on_write(uv_write_t* req, int status) {
static JSBool luv_write(JSContext* cx, unsigned argc, jsval* vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_stream_t* stream;
- stream = (uv_stream_t*)JS_GetPrivate(this);
-
JSString* str;
JSObject* callback;
+ uv_buf_t* buf;
+ size_t len;
+ luv_ref_t* ref;
+ uv_write_t* req;
+
+ stream = (uv_stream_t*)JS_GetPrivate(this);
+
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "So", &str, &callback)) {
return JS_FALSE;
}
/* Put the string in a new uv_buf_t */
- uv_buf_t* buf = (uv_buf_t*)malloc(sizeof(uv_buf_t));
- size_t len = JS_GetStringEncodingLength(cx, str);
+ buf = (uv_buf_t*)malloc(sizeof(uv_buf_t));
+ len = JS_GetStringEncodingLength(cx, str);
buf->base = (char*)malloc(len);
buf->len = JS_EncodeStringToBuffer(str, buf->base, len);
/* Store a reference to the callback in the write request */
- luv_ref_t* ref = LUV_REF(cx, callback);
- uv_write_t* req = (uv_write_t*)malloc(sizeof(uv_write_t));
+ ref = LUV_REF(cx, callback);
+ req = (uv_write_t*)malloc(sizeof(uv_write_t));
req->data = ref;
UV_CALL(uv_write, req, stream, buf, 1, luv_on_write);
@@ -190,7 +200,7 @@ static JSFunctionSpec Stream_methods[] = {
int luv_stream_init(JSContext* cx, JSObject *uv) {
Stream_prototype = JS_InitClass(cx, uv, Handle_prototype,
- &Stream_class, Stream_constructor, 0,
+ &Stream_class, Stream_constructor, 0,
NULL, Stream_methods, NULL, NULL);
return 0;
}
View
23 src/luv_tcp.c
@@ -13,13 +13,14 @@ static JSClass Tcp_class = {
static JSBool Tcp_constructor(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* obj = JS_NewObject(cx, &Tcp_class, Tcp_prototype, NULL);
+ luv_ref_t* ref;
uv_tcp_t* handle = malloc(sizeof(uv_tcp_t));
uv_tcp_init(uv_default_loop(), handle);
JS_SetPrivate(obj, handle);
/* Store a reference to the object in the handle */
- luv_ref_t* ref = LUV_REF(cx, obj);
+ ref = LUV_REF(cx, obj);
handle->data = ref;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
@@ -34,16 +35,18 @@ static void Tcp_finalize(JSContext *cx, JSObject *this) {
static JSBool luv_tcp_bind(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_tcp_t* handle;
- handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
-
-
JSString* str;
int port;
+ char *host;
+ struct sockaddr_in address;
+
+ handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
+
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "Si", &str, &port)) {
return JS_FALSE;
}
- char *host = JS_EncodeString(cx, str);
- struct sockaddr_in address = uv_ip4_addr(host, port);
+ host = JS_EncodeString(cx, str);
+ address = uv_ip4_addr(host, port);
JS_free(cx, host);
UV_CALL(uv_tcp_bind, handle, address);
@@ -55,11 +58,12 @@ static JSBool luv_tcp_bind(JSContext *cx, unsigned argc, jsval *vp) {
static JSBool luv_tcp_nodelay(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_tcp_t* handle;
- handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
/* TODO: don't hardcode */
int enable = 1;
+ handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
+
UV_CALL(uv_tcp_nodelay, handle, enable);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
@@ -69,12 +73,13 @@ static JSBool luv_tcp_nodelay(JSContext *cx, unsigned argc, jsval *vp) {
static JSBool luv_tcp_keepalive(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_tcp_t* handle;
- handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
/* TODO: don't hardcode */
int enable = 1;
int delay = 500;
+ handle = (uv_tcp_t*)JS_GetInstancePrivate(cx, this, &Tcp_class, NULL);
+
UV_CALL(uv_tcp_keepalive, handle, enable, delay);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
@@ -90,7 +95,7 @@ static JSFunctionSpec Tcp_methods[] = {
int luv_tcp_init(JSContext* cx, JSObject *uv) {
Tcp_prototype = JS_InitClass(cx, uv, Stream_prototype,
- &Tcp_class, Tcp_constructor, 0,
+ &Tcp_class, Tcp_constructor, 0,
NULL, Tcp_methods, NULL, NULL);
return 0;
}
View
20 src/luv_timer.c
@@ -13,13 +13,15 @@ static JSClass Timer_class = {
static JSBool Timer_constructor(JSContext *cx, unsigned argc, jsval *vp) {
JSObject* obj = JS_NewObject(cx, &Timer_class, Timer_prototype, NULL);
+ uv_timer_t* handle;
+ luv_ref_t* ref;
- uv_timer_t* handle = malloc(sizeof(uv_timer_t));
+ handle = malloc(sizeof(uv_timer_t));
uv_timer_init(uv_default_loop(), handle);
JS_SetPrivate(obj, handle);
/* Store a reference to the object in the handle */
- luv_ref_t* ref = LUV_REF(cx, obj);
+ ref = LUV_REF(cx, obj);
handle->data = ref;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
@@ -44,11 +46,12 @@ void luv_on_timer(uv_timer_t* handle, int status) {
static JSBool luv_timer_start(JSContext* cx, unsigned argc, jsval *vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_timer_t* handle;
- handle = (uv_timer_t*)JS_GetInstancePrivate(cx, this, &Timer_class, NULL);
-
int32_t timeout;
int32_t repeat;
JSObject* callback;
+
+ handle = (uv_timer_t*)JS_GetInstancePrivate(cx, this, &Timer_class, NULL);
+
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "uuo", &timeout, &repeat, &callback)) {
return JS_FALSE;
}
@@ -86,9 +89,10 @@ static JSBool luv_timer_again(JSContext* cx, unsigned argc, jsval* vp) {
static JSBool luv_timer_set_repeat(JSContext* cx, unsigned argc, jsval* vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_timer_t* handle;
+ int32_t repeat;
+
handle = (uv_timer_t*)JS_GetInstancePrivate(cx, this, &Timer_class, NULL);
- int32_t repeat;
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "u", &repeat)) {
return JS_FALSE;
}
@@ -102,9 +106,11 @@ static JSBool luv_timer_set_repeat(JSContext* cx, unsigned argc, jsval* vp) {
static JSBool luv_timer_get_repeat(JSContext* cx, unsigned argc, jsval* vp) {
JSObject* this = JS_THIS_OBJECT(cx, vp);
uv_timer_t* handle;
+ int64_t repeat;
+
handle = (uv_timer_t*)JS_GetInstancePrivate(cx, this, &Timer_class, NULL);
- int64_t repeat = uv_timer_get_repeat(handle);
+ repeat = uv_timer_get_repeat(handle);
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(repeat));
return JS_TRUE;
@@ -122,7 +128,7 @@ static JSFunctionSpec Timer_methods[] = {
int luv_timer_init(JSContext* cx, JSObject *uv) {
Timer_prototype = JS_InitClass(cx, uv, Handle_prototype,
- &Timer_class, Timer_constructor, 0,
+ &Timer_class, Timer_constructor, 0,
NULL, Timer_methods, NULL, NULL);
return 0;
}
View
27 src/main.c
@@ -69,21 +69,23 @@ static JSBool Exit(JSContext *cx, unsigned argc, jsval *vp) {
}
static JSBool executeFile(JSContext *cx, unsigned argc, jsval *vp) {
-
JSString* str;
JSObject* obj;
+ char *filename;
+ JSScript* script;
+ jsval result;
+
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "So", &str, &obj)) {
return JS_FALSE;
}
- char *filename = JS_EncodeString(cx, str);
+ filename = JS_EncodeString(cx, str);
- JSScript* script = JS_CompileUTF8File(cx, JS_THIS_OBJECT(cx, vp), filename);
+ script = JS_CompileUTF8File(cx, JS_THIS_OBJECT(cx, vp), filename);
JS_free(cx, filename);
if (!script) {
return JS_FALSE;
}
- jsval result;
if (!JS_ExecuteScript(cx, obj, script, &result)) {
return JS_FALSE;
}
@@ -107,11 +109,17 @@ static JSFunctionSpec binding_functions[] = {
int main(int argc, const char *argv[])
{
+ int index;
/* JS variables. */
JSRuntime* rt;
JSContext* cx;
JSObject* global;
+ JSObject* alpha;
+ JSObject* bindings;
+ jsval global_val;
+ JSObject* args;
+ jsval args_val;
/* Create a JS runtime. */
rt = JS_NewRuntime(8L * 1024L * 1024L);
@@ -134,24 +142,23 @@ int main(int argc, const char *argv[])
like Object and Array. */
if (!JS_InitStandardClasses(cx, global)) return 1;
- JSObject* alpha = JS_DefineObject(cx, global, "alpha", NULL, NULL, 0);
+ alpha = JS_DefineObject(cx, global, "alpha", NULL, NULL, 0);
/* Attach the global functions */
if (!JS_DefineFunctions(cx, alpha, global_functions)) return 1;
/* expose the binding functions for require to use */
- JSObject* bindings = JS_DefineObject(cx, alpha, "bindings", NULL, NULL, 0);
+ bindings = JS_DefineObject(cx, alpha, "bindings", NULL, NULL, 0);
if (!JS_DefineFunctions(cx, bindings, binding_functions)) return 1;
/* Set global on alpha */
- jsval global_val = OBJECT_TO_JSVAL(global);
+ global_val = OBJECT_TO_JSVAL(global);
if (!JS_SetProperty(cx, alpha, "global", &global_val)) return 1;
/* Set args on alpha */
- JSObject* args = JS_NewArrayObject(cx, 0, NULL);
- jsval args_val = OBJECT_TO_JSVAL(args);
+ args = JS_NewArrayObject(cx, 0, NULL);
+ args_val = OBJECT_TO_JSVAL(args);
if (!JS_SetProperty(cx, alpha, "args", &args_val)) return 1;
- int index;
for (index = 0; index < argc; index++) {
jsval arg = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, argv[index]));
if (!JS_SetElement(cx, args, index, &arg)) return 1;
View
2  tools/js2c.py
@@ -33,7 +33,7 @@ def main():
for source_file in source_files:
lines = ReadFile(source_file)
# lines = RemoveCommentsAndTrailingWhitespace(lines)
- var_name = "embedded_" + re.sub(r'[./]', '_', source_file)
+ var_name = "embedded_" + re.sub(r'[./\\]', '_', source_file)
o = "const char " + var_name + "[] = {\n" + ToCAsciiArray(lines + "\0") + "\n};\n"
output.write(o)
Please sign in to comment.
Something went wrong with that request. Please try again.