[Pkg-mozext-commits] [adblock-plus] 15/464: A little less likely to break because of GC problems. Just don't set GCzeal.

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 e1d9221749e4775f3f57e0e0f6d807093e45a48f
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date:   Tue Feb 17 13:40:33 2009 -0500

    A little less likely to break because of GC problems. Just don't set GCzeal.
---
 Makefile           |  2 +-
 jshydra.cpp        |  6 +++++-
 jshydra_bridge.cpp | 19 +++++++++++++++++--
 jshydra_bridge.h   |  2 ++
 tests/ast.js       | 14 +++++++++++++-
 tests/basic.js     |  1 +
 6 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index d4137c5..11ebdb0 100644
--- a/Makefile
+++ b/Makefile
@@ -21,4 +21,4 @@ jshydra.o: jshydra.cpp
 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
+	g++ -o jshydra_bridge.o -g $(INCLUDE) -c jshydra_bridge.cpp -DDEBUG
diff --git a/jshydra.cpp b/jshydra.cpp
index aa3930c..b888776 100644
--- a/jshydra.cpp
+++ b/jshydra.cpp
@@ -117,6 +117,8 @@ TokenValue tokens[] = {
 JSObject *makeNode(JSParseNode *node) {
 	if (!node)
 		return NULL;
+	if (!JS_EnterLocalRootScope(cx))
+		return NULL;
 	JSObject *object = JS_NewObject(cx, &js_node_class, NULL, NULL);
 	setIntProperty(object, "line", node->pn_pos.begin.lineno);
 	setIntProperty(object, "column", node->pn_pos.begin.index);
@@ -176,7 +178,7 @@ JSObject *makeNode(JSParseNode *node) {
 	//case APAIR:
 	//case OBJLITERAL:
 	case DOUBLELITERAL:
-		jshydra_defineProperty(cx, object, "value", DOUBLE_TO_JSVAL(node->pn_dval));
+		jshydra_defineProperty(cx, object, "value", DOUBLE_TO_JSVAL(&node->pn_dval));
 		break;
 	case NULLARY:
 		break;
@@ -185,6 +187,7 @@ JSObject *makeNode(JSParseNode *node) {
 		fprintf(stderr, "Unexpected type: %d (arity %d)\n", node->pn_type, node->pn_arity);
 		break;
 	}
+	JS_LeaveLocalRootScope(cx);
 	return object;
 }
 
@@ -197,6 +200,7 @@ void parseFile(FILE *file, char *filename) {
 	jsval func = jshydra_getToplevelFunction(cx, "process_js");
 	if (JS_TypeOfValue(cx, func) != JSTYPE_FUNCTION) {
 		fprintf(stderr, "No function process_js!\n");
+  		JS_LeaveLocalRootScope(cx);
 		return;
 	}
 	jsval rval, argv[1];
diff --git a/jshydra_bridge.cpp b/jshydra_bridge.cpp
index 0a2d8ef..8461d03 100644
--- a/jshydra_bridge.cpp
+++ b/jshydra_bridge.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-#include <jsapi.h>
+#include "jsapi.h"
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,6 +20,8 @@ JSRuntime *rt;
 JSContext *cx;
 JSObject *globalObj;
 
+JSObject *rootArray;
+
 static char *my_dirname (char *path);
 
 JSClass js_node_class = {
@@ -46,6 +48,7 @@ void jshydra_init(const char *file) {
   rt = JS_NewRuntime (0x9000000L);
   cx = JS_NewContext (rt, 8192);
   JS_BeginRequest(cx);
+  //JS_SetGCZeal(cx, 2);
 
   //JS_SetContextPrivate (this->cx, this);
   
@@ -99,6 +102,10 @@ void jshydra_init(const char *file) {
   while (*name) {
 	  jshydra_defineProperty(cx, globalObj, *name++, INT_TO_JSVAL(index++));
   }
+
+  rootArray = JS_NewArrayObject(cx, 0, NULL);
+  JS_AddRoot(cx, &rootArray);
+  jshydra_rootObject(cx, globalObj);
 }
 
 /*int dehydra_startup (Dehydra *this) {
@@ -108,9 +115,11 @@ void jshydra_init(const char *file) {
 int jshydra_includeScript (JSContext *cx, const char *script) {
   jsval strval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, script));
   //int key = dehydra_rootObject (this, strval);
+  if (!JS_EnterLocalRootScope(cx))
+	  return -1;
   jsval rval;
   int ret = !Include (cx, globalObj, 1, &strval, &rval);
-  //dehydra_unrootObject (this, key);
+  JS_LeaveLocalRootScope(cx);
   return ret;
 }
 
@@ -247,3 +256,9 @@ jsval jshydra_getToplevelFunction(JSContext *cx, char const *name) {
           && val != JSVAL_VOID
           && JS_TypeOfValue(cx, val) == JSTYPE_FUNCTION) ? val : JSVAL_VOID;
 }
+
+void jshydra_rootObject(JSContext *cx, JSObject *obj) {
+  jsval rval, argv[1];
+  argv[0] = OBJECT_TO_JSVAL(obj);
+  JS_CallFunctionName(cx, rootArray, "push", 1, argv, &rval);
+}
diff --git a/jshydra_bridge.h b/jshydra_bridge.h
index 735ad6c..034eb25 100644
--- a/jshydra_bridge.h
+++ b/jshydra_bridge.h
@@ -27,4 +27,6 @@ void jshydra_defineProperty(JSContext *cx, JSObject *obj,
 jsuint jshydra_getArrayLength(JSContext *cx, JSObject *array);
 jsval jshydra_getToplevelFunction(JSContext *cx, char const *name);
 
+void jshydra_rootObject(JSContext *cx, JSObject *obj);
+
 #endif
diff --git a/tests/ast.js b/tests/ast.js
index 12d1c88..cc7ee73 100644
--- a/tests/ast.js
+++ b/tests/ast.js
@@ -7,5 +7,17 @@ const LS = "foobar";
 
 function process_js(ast) {
 	let toplevel = clean_ast(ast);
-	_print(uneval(toplevel));
+	_print("Global variables:");
+	for each (let v in toplevel.variables) {
+		_print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
+	}
+	_print("Global constants:");
+	for each (let v in toplevel.constants) {
+		_print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
+	}
+	_print("Global functions:");
+	for each (let v in toplevel.functions) {
+		_print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
+		_print(v.body.kids[0].column);
+	}
 }
diff --git a/tests/basic.js b/tests/basic.js
index 80a6207..ecf8d9b 100644
--- a/tests/basic.js
+++ b/tests/basic.js
@@ -1,6 +1,7 @@
 // Run ../jshydra basic.js basic.js: it should work.
 // This is a simple test just to make sure that something isn't borking with
 // jshydra.
+_print("HI!");
 function process_js(ast) {
 	for (f in ast) {
 		_print(f + ": "+ ast[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