Mercurial > spidermonkey-playground
changeset 40:f86740dc5fa0
Added an almost-completely-unimplemented TCP server socket object that uses NSPR.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 24 Jun 2009 13:01:11 -0700 |
parents | 067371eb9601 |
children | f495677654fc |
files | pavement.py server_socket.cpp server_socket.h spidermonkey-playground.cpp tcb.js |
diffstat | 5 files changed, 148 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/pavement.py Tue Jun 23 12:32:39 2009 -0700 +++ b/pavement.py Wed Jun 24 13:01:11 2009 -0700 @@ -11,9 +11,14 @@ incdir = os.path.join(objdir, "include") libdir = os.path.join(objdir, "lib") - cmdline = ["g++", "spidermonkey-playground.cpp", "wrapper.cpp", + cmdline = ["g++", "-o", "spidermonkey-playground", - "-I%s" % incdir, "-L%s" % libdir, "-lmozjs"] + "-I%s" % incdir, "-L.", + "spidermonkey-playground.cpp", + "wrapper.cpp", + "server_socket.cpp", + "-lmozjs", + "-lnspr4"] for dylib in ["mozjs", "plds4", "plc4", "nspr4"]: name = "lib%s.dylib" % dylib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server_socket.cpp Wed Jun 24 13:01:11 2009 -0700 @@ -0,0 +1,85 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ubiquity. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Atul Varma <atul@mozilla.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "server_socket.h" + +#include "nspr.h" + +static void finalize(JSContext *cx, JSObject *obj) +{ + PRFileDesc *fd = (PRFileDesc *) JS_GetPrivate(cx, obj); + // Just in case, ensure we don't have a dangling pointer. + JS_SetPrivate(cx, obj, NULL); + PR_Close(fd); +} + +JSExtendedClass sServerSocket_JSClass = { + // JSClass (JSExtendedClass.base) initialization + { "FlexibleWrapper", + JSCLASS_IS_EXTENDED | JSCLASS_HAS_PRIVATE | + JSCLASS_HAS_RESERVED_SLOTS(0), + JS_PropertyStub, JS_PropertyStub, + JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, + JS_ConvertStub, finalize, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL + }, + // JSExtendedClass initialization + NULL, // equality + NULL, // outerObject + NULL, // innerObject + NULL, // iterator + NULL, // wrapper + JSCLASS_NO_RESERVED_MEMBERS +}; + +JSBool createServerSocket(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + JSObject *object = JS_NewObject( + cx, + &sServerSocket_JSClass.base, + NULL, + JS_GetScopeChain(cx) + ); + PRFileDesc *fd = PR_OpenTCPSocket(PR_AF_INET); + JS_SetPrivate(cx, object, fd); + *rval = OBJECT_TO_JSVAL(object); + return JS_TRUE; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server_socket.h Wed Jun 24 13:01:11 2009 -0700 @@ -0,0 +1,41 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ubiquity. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Atul Varma <atul@mozilla.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "jsapi.h" + +extern JSExtendedClass sServerSocket_JSClass; +extern JSBool createServerSocket(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval);
--- a/spidermonkey-playground.cpp Tue Jun 23 12:32:39 2009 -0700 +++ b/spidermonkey-playground.cpp Wed Jun 24 13:01:11 2009 -0700 @@ -44,6 +44,7 @@ #include "jsdhash.h" #include "wrapper.h" +#include "server_socket.h" // The name of our JS script containing our Trusted Code Base (TCB). #define TCB_FILENAME "tcb.js" @@ -480,17 +481,18 @@ } static JSFunctionSpec tcb_global_functions[] = { - JS_FS("print", print, 1, 0, 0), - JS_FS("getWrapper", getWrapper, 1, 0, 0), - JS_FS("unwrap", unwrapObject, 1, 0, 0), - JS_FS("wrap", wrapObject, 2, 0, 0), - JS_FS("stack", stack, 0, 0, 0), - JS_FS("require", require, 2, 0, 0), - JS_FS("lookupProperty", lookupProperty, 2, 0, 0), - JS_FS("functionInfo", functionInfo, 1, 0, 0), - JS_FS("enumerate", enumerate, 1, 0, 0), - JS_FS("forceGC", forceGC, 0, 0, 0), - JS_FS("dumpHeap", dumpHeap, 0, 0, 0), + JS_FS("print", print, 1, 0, 0), + JS_FS("getWrapper", getWrapper, 1, 0, 0), + JS_FS("unwrap", unwrapObject, 1, 0, 0), + JS_FS("wrap", wrapObject, 2, 0, 0), + JS_FS("stack", stack, 0, 0, 0), + JS_FS("require", require, 2, 0, 0), + JS_FS("lookupProperty", lookupProperty, 2, 0, 0), + JS_FS("functionInfo", functionInfo, 1, 0, 0), + JS_FS("enumerate", enumerate, 1, 0, 0), + JS_FS("forceGC", forceGC, 0, 0, 0), + JS_FS("dumpHeap", dumpHeap, 0, 0, 0), + JS_FS("Socket", createServerSocket, 0, 0, 0), JS_FS_END };