diff options
author | Colin Walters <walters@verbum.org> | 2010-09-20 12:11:21 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-09-20 12:11:21 -0400 |
commit | f4f2e917ae9b8ff986291aa0bfbad4792b508a39 (patch) | |
tree | 8927554db271c1fe62c1ec192e1ed2d091d8c626 | |
parent | f8143c75ef136c0040589f3d9aa16f8931c87406 (diff) | |
download | gjs-f4f2e917ae9b8ff986291aa0bfbad4792b508a39.tar.gz |
Remove "debugger" module
Exposing the error hook to JS was a cute hack, but the way it's
implemented is problematic; see
https://bugzilla.gnome.org/show_bug.cgi?id=630179
-rw-r--r-- | Makefile-modules.am | 14 | ||||
-rw-r--r-- | modules/debugger.c | 138 | ||||
-rw-r--r-- | modules/debugger.h | 39 | ||||
-rw-r--r-- | test/js/testDebugger.js | 43 |
4 files changed, 1 insertions, 233 deletions
diff --git a/Makefile-modules.am b/Makefile-modules.am index c43b2d80..30b19c6e 100644 --- a/Makefile-modules.am +++ b/Makefile-modules.am @@ -12,7 +12,7 @@ dist_gjsjs_DATA += \ modules/dbus.js \ modules/promise.js -gjsnative_LTLIBRARIES += console.la debugger.la gi.la langNative.la mainloop.la gettextNative.la dbusNative.la cairoNative.la +gjsnative_LTLIBRARIES += console.la gi.la langNative.la mainloop.la gettextNative.la dbusNative.la cairoNative.la JS_NATIVE_MODULE_CFLAGS = \ $(AM_CFLAGS) \ @@ -116,18 +116,6 @@ console_la_SOURCES = \ modules/console.h \ modules/console.c -debugger_la_CFLAGS = \ - $(JS_NATIVE_MODULE_CFLAGS) -debugger_la_LIBADD = \ - libgjs-gi.la \ - $(JS_NATIVE_MODULE_LIBADD) -debugger_la_LDFLAGS = \ - $(JS_NATIVE_MODULE_LDFLAGS) - -debugger_la_SOURCES = \ - modules/debugger.h \ - modules/debugger.c - dbusNative_la_SOURCES = \ modules/dbus-exports.h \ modules/dbus-values.h \ diff --git a/modules/debugger.c b/modules/debugger.c deleted file mode 100644 index b2c60a5e..00000000 --- a/modules/debugger.c +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -/* - * Copyright (c) 2008 litl, LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include <string.h> - -#include <jsapi.h> -#include <jsdbgapi.h> - -#include <glib.h> -#include <gjs/gjs.h> -#include <gi/closure.h> - -#include "debugger.h" - -static void -closure_invalidated(gpointer data, - GClosure *closure) -{ - g_closure_remove_invalidate_notifier(closure, closure, - closure_invalidated); - g_closure_unref(closure); -} - -static JSBool -gjs_debugger_debug_error_hook(JSContext *context, - const char *message, - JSErrorReport *report, - void *user_data) -{ - const char *filename = NULL; - static gboolean running = FALSE; - guint line = 0, pos = 0, flags = 0, errnum = 0; - jsval retval = JSVAL_NULL, exc; - GClosure *closure = (GClosure*)user_data; - - if (running) - return JS_FALSE; - - running = TRUE; - if (report) { - filename = report->filename; - line = report->lineno; - pos = report->tokenptr - report->linebuf; - flags = report->flags; - errnum = report->errorNumber; - } - - if (JS_IsExceptionPending(context)) { - JS_GetPendingException(context, &exc); - } else { - exc = JSVAL_NULL; - } - - if (!gjs_closure_invoke_simple(context, closure, &retval, "ssiiiiv", - message, filename, line, pos, - flags, errnum, exc)) - return JS_FALSE; - - running = FALSE; - return JS_TRUE; -} - -static JSBool -gjs_debugger_set_debug_error_hook(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) -{ - static GClosure *closure = NULL; - JSRuntime *runtime; - - if (!(argc == 1) || - !JSVAL_IS_OBJECT(argv[0])) { - gjs_throw(context, "setDebugErrorHook takes 1 argument, " - " the callback"); - return JS_FALSE; - } - - if (closure != NULL) { - *retval = OBJECT_TO_JSVAL(gjs_closure_get_callable(closure)); - g_closure_invalidate(closure); - closure = NULL; - } - - runtime = JS_GetRuntime(context); - - if (argv[0] == JSVAL_NULL) { - JS_SetDebugErrorHook(runtime, NULL, NULL); - } else { - closure = gjs_closure_new(context, - JSVAL_TO_OBJECT(argv[0]), - "debugger DebugErrorHook"); - g_closure_ref(closure); - g_closure_sink(closure); - g_closure_add_invalidate_notifier(closure, closure, - closure_invalidated); - - JS_SetDebugErrorHook(runtime, gjs_debugger_debug_error_hook, closure); - } - - return JS_TRUE; -} - -JSBool -gjs_define_debugger_stuff(JSContext *context, - JSObject *module_obj) -{ - if (!JS_DefineFunction(context, module_obj, - "setDebugErrorHook", - gjs_debugger_set_debug_error_hook, - 1, GJS_MODULE_PROP_FLAGS)) - return JS_FALSE; - - return JS_TRUE; -} - -GJS_REGISTER_NATIVE_MODULE("debugger", gjs_define_debugger_stuff); diff --git a/modules/debugger.h b/modules/debugger.h deleted file mode 100644 index 2c61edcb..00000000 --- a/modules/debugger.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ -/* - * Copyright (c) 2008 litl, LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef __GJS_DEBUGGER_H__ -#define __GJS_DEBUGGER_H__ - -#include <config.h> -#include <glib.h> - -#include <jsapi.h> - -G_BEGIN_DECLS - -JSBool gjs_define_debugger_stuff (JSContext *context, - JSObject *in_object); - -G_END_DECLS - -#endif /* __GJS_DEBUGGER_H__ */ diff --git a/test/js/testDebugger.js b/test/js/testDebugger.js deleted file mode 100644 index aab23863..00000000 --- a/test/js/testDebugger.js +++ /dev/null @@ -1,43 +0,0 @@ -// tests for imports.debugger module - -const Debugger = imports.debugger; - -function testSetDebugErrorHook() { - let args; - - let errorHook = function(message, filename, line, pos, flags, errnum, exc) { - args = { message: message, - filename: filename, - line: line, - pos: pos, - flags: flags, - errnum: errnum, - exc: exc }; - }; - - let faulty = function() { - /* This is a non-obvious way to get a warning - * just to workaround the error detection in js2-mode. - * */ - new String(faulty['undefinedProperty']); - }; - - let old = Debugger.setDebugErrorHook(errorHook); - assertUndefined(old); - faulty(); - old = Debugger.setDebugErrorHook(null); - assertEquals(old, errorHook); - - assertNotUndefined(args); - assertEquals("reference to undefined property faulty.undefinedProperty", args.message); - assertEquals("args.line", 22, args.line); - assertEquals("args.pos", 0, args.pos); - assertEquals("args.flags", 5, args.flags); - assertEquals("args.errnum", 162, args.errnum); - assertNotUndefined("args.exc", args.exc); - - assertRaises(function() { Debugger.setDebugErrorHook(); }); - -} - -gjstestRun(); |