Add an empty Debug constructor into the shell and a JS_DefineDebugObject function to jsdbgapi.h.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 14 Apr 2011 13:41:31 -0700
changeset 74379 2684c36f33e68b4cd938db38a4bef48a491490d1
parent 67933 722ab9ce914e02776b6c0f74249772ff4afe7261
child 74380 090fcf731131e25c5c73525869f852cad259f7f4
push id20986
push userkhuey@mozilla.com
push dateSun, 14 Aug 2011 11:45:15 +0000
treeherdermozilla-central@2de3cff973b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Add an empty Debug constructor into the shell and a JS_DefineDebugObject function to jsdbgapi.h.
js/src/Makefile.in
js/src/jsdbg.cpp
js/src/jsdbgapi.h
js/src/shell/js.cpp
js/src/tests/js1_8_5/extensions/debug-object-01.js
js/src/tests/js1_8_5/extensions/jstests.list
js/src/tests/js1_8_5/extensions/shell.js
js/src/tests/shell.js
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -132,16 +132,17 @@ CPPSRCS		= \
 		jsarray.cpp \
 		jsatom.cpp \
 		jsbool.cpp \
 		jsclone.cpp \
 		jscntxt.cpp \
 		jscompartment.cpp \
 		jsdate.cpp \
 		jsdbgapi.cpp \
+		jsdbg.cpp \
 		jsdhash.cpp \
 		jsdtoa.cpp \
 		jsemit.cpp \
 		jsexn.cpp \
 		jsfriendapi.cpp \
 		jsfun.cpp \
 		jsgc.cpp \
 		jsgcchunk.cpp \
new file mode 100644
--- /dev/null
+++ b/js/src/jsdbg.cpp
@@ -0,0 +1,73 @@
+/* ***** 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 SpiderMonkey Debug object.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-1999
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Jim Blandy <jimb@mozilla.com>
+ *   Jason Orendorff <jorendorff@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of 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"
+#include "jscntxt.h"
+#include "jsobj.h"
+
+using namespace js;
+
+static bool
+NotImplemented(JSContext *cx)
+{
+    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NEED_DIET, "API");
+    return false;
+}
+
+static JSBool
+Debug(JSContext *cx, uintN argc, Value *vp)
+{
+    return NotImplemented(cx);
+}
+
+static Class DebugClass = {
+    "Debug", 0,
+    PropertyStub, PropertyStub, PropertyStub, StrictPropertyStub,
+    EnumerateStub, ResolveStub, ConvertStub
+};
+
+extern JS_PUBLIC_API(JSBool)
+JS_DefineDebugObject(JSContext *cx, JSObject *obj)
+{
+    JSObject *objProto;
+    if (!js_GetClassPrototype(cx, obj, JSProto_Object, &objProto))
+        return NULL;
+
+    return !!js_InitClass(cx, obj, objProto, &DebugClass, Debug, 1,
+                          NULL, NULL, NULL, NULL);
+}
--- a/js/src/jsdbgapi.h
+++ b/js/src/jsdbgapi.h
@@ -519,16 +519,20 @@ extern JS_PUBLIC_API(JSBool)
 JS_StartProfiling();
 
 extern JS_PUBLIC_API(void)
 JS_StopProfiling();
 
 extern JS_PUBLIC_API(JSBool)
 JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj);
 
+/* Defined in jsdbg.cpp. */
+extern JS_PUBLIC_API(JSBool)
+JS_DefineDebugObject(JSContext *cx, JSObject *obj);
+
 #ifdef MOZ_CALLGRIND
 
 extern JS_FRIEND_API(JSBool)
 js_StopCallgrind(JSContext *cx, uintN argc, jsval *vp);
 
 extern JS_FRIEND_API(JSBool)
 js_StartCallgrind(JSContext *cx, uintN argc, jsval *vp);
 
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -5700,16 +5700,18 @@ NewGlobalObject(JSContext *cx, Compartme
         if (!JS_InitStandardClasses(cx, glob))
             return NULL;
 #endif
 
 #ifdef JS_HAS_CTYPES
         if (!JS_InitCTypesClass(cx, glob))
             return NULL;
 #endif
+        if (!JS_DefineDebugObject(cx, glob))
+            return NULL;
         if (!JS::RegisterPerfMeasurement(cx, glob))
             return NULL;
         if (!JS_DefineFunctions(cx, glob, shell_functions) ||
             !JS_DefineProfilingFunctions(cx, glob)) {
             return NULL;
         }
 
         JSObject *it = JS_DefineObject(cx, glob, "it", &its_class, NULL, 0);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/debug-object-01.js
@@ -0,0 +1,10 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+checkFunction(this, "Debug", 1);
+
+assertEq(Debug.prototype.constructor, Debug);
+assertEq(Object.prototype.toString.call(Debug.prototype), "[object Debug]");
+assertEq(Object.getPrototypeOf(Debug.prototype), Object.prototype);
+
+reportCompare(0, 0, 'ok');
--- a/js/src/tests/js1_8_5/extensions/jstests.list
+++ b/js/src/tests/js1_8_5/extensions/jstests.list
@@ -34,8 +34,9 @@ script regress-627984-3.js
 script regress-627984-4.js
 script regress-627984-5.js
 script regress-627984-6.js
 script regress-627984-7.js
 script regress-630377.js
 script regress-631723.js
 skip-if(!xulRuntime.shell) script regress-636818.js
 script regress-636697.js
+skip-if(!xulRuntime.shell) script debug-object-01.js
--- a/js/src/tests/js1_8_5/extensions/shell.js
+++ b/js/src/tests/js1_8_5/extensions/shell.js
@@ -165,8 +165,19 @@ var Match =
 
         return matchObject(act, exp);
     }
 
     return { Pattern: Pattern,
              MatchError: MatchError };
 
 })();
+
+// used by several Debug object tests
+function checkFunction(obj, name, nargs) {
+    var desc = Object.getOwnPropertyDescriptor(obj, name);
+    assertEq(desc.configurable, true, name + " should be configurable");
+    assertEq(desc.writable, true, name + " should be writable");
+    assertEq(desc.enumerable, false, name + " should be non-enumerable");
+    assertEq(desc.value, obj[name]);  // well obviously
+    assertEq(typeof desc.value, 'function', name + " should be a function");
+    assertEq(desc.value.length, nargs, name + " should have .length === " + nargs);
+}
--- a/js/src/tests/shell.js
+++ b/js/src/tests/shell.js
@@ -274,16 +274,34 @@ if (typeof assertEq == 'undefined')
       if (!SameValue(actual, expected))
       {
         throw new TypeError('Assertion failed: got "' + actual + '", expected "' + expected +
                             (message ? ": " + message : ""));
       }
     };
 }
 
+if (typeof assertThrows === 'undefined') {
+    var assertThrows = function assertThrows(f, ctor, msg) {
+        var fullmsg;
+        try {
+            f();
+        } catch (exc) {
+            if (exc instanceof ctor)
+                return;
+            fullmsg = "Assertion failed: expected exception " + ctor.name + ", got " + exc;
+        }
+        if (fullmsg === undefined)
+            fullmsg = "Assertion failed: expected exception " + ctor.name +", no exception thrown";
+        if (msg !== undefined)
+            fullmsg += " - " + msg;
+        throw new Error(fullmsg);
+    };
+}
+
 /*
  * Compare expected result to actual result, if they differ (in value and/or
  * type) report a failure.  If description is provided, include it in the
  * failure report.
  */
 function reportCompare (expected, actual, description) {
   var expected_t = typeof expected;
   var actual_t = typeof actual;