[Pkg-mozext-commits] [adblock-plus] 13/464: Now in C++ for easier compiling!
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:43:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit c9c7d5c131cb592b0cca0271d45e2546796a3284
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date: Fri Jan 30 12:07:09 2009 -0500
Now in C++ for easier compiling!
--HG--
rename : jshydra.c => jshydra.cpp
rename : jshydra_bridge.c => jshydra_bridge.cpp
rename : jshydra_funcs.c => jshydra_funcs.cpp
---
Makefile | 12 ++++++------
jshydra.c => jshydra.cpp | 22 ++++------------------
jshydra_bridge.c => jshydra_bridge.cpp | 22 +++++++++++++++++++---
jshydra_funcs.c => jshydra_funcs.cpp | 24 ++++++++++++------------
4 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/Makefile b/Makefile
index 857d631..d4137c5 100644
--- a/Makefile
+++ b/Makefile
@@ -15,10 +15,10 @@ OBJS := $(addprefix /src/build/trunk/browser/js/src/, $(OBJS))
jshydra: jshydra.o jshydra_funcs.o jshydra_bridge.o
g++ -o jshydra jshydra.o jshydra_funcs.o jshydra_bridge.o $(OBJS) $(LINK)
-jshydra.o: jshydra.c
- gcc -o jshydra.o -g $(INCLUDE) -c jshydra.c
+jshydra.o: jshydra.cpp
+ g++ -o jshydra.o -g $(INCLUDE) -c jshydra.cpp
-jshydra_funcs.o: jshydra_funcs.c
- gcc -o jshydra_funcs.o -g $(INCLUDE) -c jshydra_funcs.c
-jshydra_bridge.o: jshydra_bridge.c
- gcc -o jshydra_bridge.o -g $(INCLUDE) -c jshydra_bridge.c
+jshydra_funcs.o: jshydra_funcs.cpp
+ g++ -o jshydra_funcs.o -g $(INCLUDE) -c jshydra_funcs.cpp
+jshydra_bridge.o: jshydra_bridge.cpp
+ g++ -o jshydra_bridge.o -g $(INCLUDE) -c jshydra_bridge.cpp
diff --git a/jshydra.c b/jshydra.cpp
similarity index 93%
rename from jshydra.c
rename to jshydra.cpp
index b57e314..972d54b 100644
--- a/jshydra.c
+++ b/jshydra.cpp
@@ -1,5 +1,3 @@
-typedef int bool;
-
#include "jsapi.h"
#include "jsparse.h"
#include "jscntxt.h"
@@ -7,18 +5,6 @@ typedef int bool;
#include "jshydra_bridge.h"
-/*static JSRuntime *rt;
-static JSContext *cx;
-static JSObject *globalObject;*/
-
-static char *opcodes[] = {
-#define OPDEF(op, val, name, image, len, use, def, prec, format) \
- #op,
-#include "jsopcode.tbl"
-#undef OPDEF
- NULL
-};
-
void setIntProperty(JSObject *obj, const char *name, int value) {
jshydra_defineProperty(cx, obj, name, INT_TO_JSVAL(value));
}
@@ -39,7 +25,7 @@ typedef enum TokenValue {
} TokenValue;
TokenValue tokens[] = {
- ERROR, /*TOK_EOF*/
+ NULLARY, /*TOK_EOF*/
ERROR, /*TOK_EOL*/
UNARY, /*TOK_SEMI*/
LIST, /*TOK_COMMA*/
@@ -84,7 +70,7 @@ TokenValue tokens[] = {
BINARY, /*TOK_FOR*/
NAME, /*TOK_BREAK*/
NAME, /*TOK_CONTINUE*/
- ERROR, /*TOK_IN*/
+ BINARY, /*TOK_IN*/
LIST, /*TOK_VAR*/
BINARY, /*TOK_WITH*/
UNARY, /*TOK_RETURN*/
@@ -176,7 +162,7 @@ JSObject *makeNode(JSParseNode *node) {
break;
}
case NAME: {
- JS_DefineProperty(cx, object, "atom", ATOM_KEY(node->pn_atom), NULL, NULL, JSPROP_READONLY);
+ JS_DefineProperty(cx, object, "atom", ATOM_KEY(node->pn_atom), NULL, NULL, JSPROP_READONLY | JSPROP_ENUMERATE);
JSObject *array = JS_NewArrayObject(cx, 0, NULL);
setArrayElement(array, 0, makeNode(node->pn_expr));
setObjectProperty(object, "kids", array);
@@ -192,7 +178,7 @@ JSObject *makeNode(JSParseNode *node) {
break;
case ERROR:
default:
- fprintf(stderr, "Unexpected type: %d\n", node->pn_type);
+ fprintf(stderr, "Unexpected type: %d (arity %d)\n", node->pn_type, node->pn_arity);
break;
}
return object;
diff --git a/jshydra_bridge.c b/jshydra_bridge.cpp
similarity index 92%
rename from jshydra_bridge.c
rename to jshydra_bridge.cpp
index d63c02d..0a2d8ef 100644
--- a/jshydra_bridge.c
+++ b/jshydra_bridge.cpp
@@ -3,10 +3,19 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "jshydra_bridge.h"
#include "jshydra_funcs.h"
+static const char *opcodes[] = {
+#define OPDEF(op, val, name, image, len, use, def, prec, format) \
+ #op,
+#include "jsopcode.tbl"
+#undef OPDEF
+ NULL
+};
+
JSRuntime *rt;
JSContext *cx;
JSObject *globalObj;
@@ -71,7 +80,7 @@ void jshydra_init(const char *file) {
char *filename_copy = strdup(file);
char *dir = my_dirname(filename_copy);
jshydra_appendToPath(cx, dir);
- char *libdir = malloc(strlen(dir) + strlen("libs") + 2);
+ char *libdir = static_cast<char *>(malloc(strlen(dir) + strlen("libs") + 2));
sprintf(libdir, "%s/%s", dir, "libs");
jshydra_appendToPath(cx, libdir);
free(libdir);
@@ -83,6 +92,13 @@ void jshydra_init(const char *file) {
//}
xassert (JS_InitClass(cx, globalObj, NULL
,&js_node_class , NULL, 0, NULL, NULL, NULL, NULL));
+
+ /* Define the token properties. */
+ const char **name = opcodes;
+ jsint index = 0;
+ while (*name) {
+ jshydra_defineProperty(cx, globalObj, *name++, INT_TO_JSVAL(index++));
+ }
}
/*int dehydra_startup (Dehydra *this) {
@@ -150,9 +166,9 @@ FILE *jshydra_searchPath (JSContext *cx, const char *filename, char **realname)
if (!dir_str) continue;
char *dir = JS_GetStringBytes(dir_str);
- char *buf = malloc(strlen(dir) + strlen(filename) + 2);
+ char *buf = static_cast<char *>(malloc(strlen(dir) + strlen(filename) + 2));
/* Doing a little extra work here to get rid of unneeded '/'. */
- char *sep = dir[strlen(dir)-1] == '/' ? "" : "/";
+ const char *sep = dir[strlen(dir)-1] == '/' ? "" : "/";
sprintf(buf, "%s%s%s", dir, sep, filename);
FILE *f = fopen(buf, "r");
if (f) {
diff --git a/jshydra_funcs.c b/jshydra_funcs.cpp
similarity index 95%
rename from jshydra_funcs.c
rename to jshydra_funcs.cpp
index 961b03a..d60e160 100644
--- a/jshydra_funcs.c
+++ b/jshydra_funcs.cpp
@@ -124,7 +124,7 @@ JSBool Require(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
as "this" when evaluating the script, which is effectively a namespace
for the script. */
static JSBool jshydra_loadScript (JSContext *cx, const char *filename,
- JSObject *namespace) {
+ JSObject *ns) {
/* Read the file. There's a JS function for reading scripts, but Dehydra
wants to search for the file in different dirs. */
long size = 0;
@@ -141,7 +141,7 @@ static JSBool jshydra_loadScript (JSContext *cx, const char *filename,
return JS_FALSE;
}
- JSScript *script = JS_CompileScript(cx, namespace,
+ JSScript *script = JS_CompileScript(cx, ns,
content, size, realname, 1);
free(realname);
if (script == NULL) {
@@ -152,7 +152,7 @@ static JSBool jshydra_loadScript (JSContext *cx, const char *filename,
JSObject *sobj = JS_NewScriptObject(cx, script);
JS_AddNamedRoot(cx, &sobj, filename);
jsval rval;
- JSBool rv = JS_ExecuteScript(cx, namespace, script, &rval);
+ JSBool rv = JS_ExecuteScript(cx, ns, script, &rval);
JS_RemoveRoot(cx, &sobj);
if (!rv) {
xassert(JS_IsExceptionPending(cx));
@@ -165,17 +165,17 @@ static JSBool jshydra_loadScript (JSContext *cx, const char *filename,
JSBool Include(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval) {
char *filename;
- JSObject *namespace = globalObj;
- if (!JS_ConvertArguments(cx, argc, argv, "s/o", &filename, &namespace))
+ JSObject *ns = globalObj;
+ if (!JS_ConvertArguments(cx, argc, argv, "s/o", &filename, &ns))
return JS_FALSE;
- *rval = OBJECT_TO_JSVAL (namespace);
+ *rval = OBJECT_TO_JSVAL (ns);
JSObject *includedArray = NULL;
jsval val;
- JS_GetProperty(cx, namespace, "_includedArray", &val);
+ JS_GetProperty(cx, ns, "_includedArray", &val);
if (!JSVAL_IS_OBJECT (val)) {
includedArray = JS_NewArrayObject (cx, 0, NULL);
- jshydra_defineProperty (cx, namespace, "_includedArray",
+ jshydra_defineProperty (cx, ns, "_includedArray",
OBJECT_TO_JSVAL (includedArray));
} else {
includedArray = JSVAL_TO_OBJECT (val);
@@ -186,7 +186,7 @@ JSBool Include(JSContext *cx, JSObject *obj, uintN argc,
}
JS_CallFunctionName (cx, includedArray, "push", 1, argv, rval);
- return jshydra_loadScript (cx, filename, namespace);
+ return jshydra_loadScript (cx, filename, ns);
}
JSBool Diagnostic(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
@@ -321,9 +321,9 @@ FILE *findFile(const char *filename, const char *dir, char **realname) {
return f;
}
if (dir && dir[0] && filename[0] && filename[0] != '/') {
- char *buf = malloc(strlen(dir) + strlen(filename) + 2);
+ char *buf = static_cast<char *>(malloc(strlen(dir) + strlen(filename) + 2));
/* Doing a little extra work here to get rid of unneeded '/'. */
- char *sep = dir[strlen(dir)-1] == '/' ? "" : "/";
+ const char *sep = dir[strlen(dir)-1] == '/' ? "" : "/";
sprintf(buf, "%s%s%s", dir, sep, filename);
f = fopen(buf, "r");
if (f) {
@@ -341,7 +341,7 @@ char *readEntireFile(FILE *f, long *size) {
if (fseek(f, 0, SEEK_END)) return NULL;
*size = ftell(f);
if (fseek(f, 0, SEEK_SET)) return NULL;
- char *buf = malloc(*size + 1);
+ char *buf = static_cast<char *>(malloc(*size + 1));
xassert(*size == fread(buf, 1, *size, f));
buf[*size] = 0;
fclose(f);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list