Bug 957926 - Add JS::CreateTypeError. r=jorendorff
authorNikhil Marathe <nsm.nikhil@gmail.com>
Tue, 28 Jan 2014 09:19:48 -0800
changeset 165627 50cfbf3d30de7789f44db29763e364c176b1dda1
parent 165626 0c3303aa3d4040aad2d134042d31985fe2c1cd27
child 165628 7e79536aca0ae7b6117115e3889400d8ff450ba1
push id4623
push userryanvm@gmail.com
push dateTue, 28 Jan 2014 21:48:39 +0000
treeherderfx-team@7e79536aca0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs957926
milestone29.0a1
Bug 957926 - Add JS::CreateTypeError. r=jorendorff
js/src/jsapi.h
js/src/jsexn.cpp
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4450,16 +4450,25 @@ struct JSErrorReport {
 #define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) &                      \
                                               JSREPORT_STRICT_MODE_ERROR) != 0)
 extern JS_PUBLIC_API(JSErrorReporter)
 JS_GetErrorReporter(JSContext *cx);
 
 extern JS_PUBLIC_API(JSErrorReporter)
 JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
 
+namespace JS {
+
+extern JS_PUBLIC_API(bool)
+CreateTypeError(JSContext *cx, HandleString stack, HandleString fileName,
+                uint32_t lineNumber, uint32_t columnNumber, JSErrorReport *report,
+                HandleString message, MutableHandleValue rval);
+
+} /* namespace JS */
+
 /************************************************************************/
 
 /*
  * Dates.
  */
 
 extern JS_PUBLIC_API(JSObject *)
 JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec);
@@ -4716,17 +4725,17 @@ class AutoHideScriptedCaller
         UnhideScriptedCaller(mContext);
     }
 
   protected:
     JSContext *mContext;
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
-} /* namepsace JS */
+} /* namespace JS */
 
 /*
  * Encode/Decode interpreted scripts and functions to/from memory.
  */
 
 extern JS_PUBLIC_API(void *)
 JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp);
 
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -863,8 +863,28 @@ js_CopyErrorObject(JSContext *cx, Handle
     uint32_t lineNumber = err->lineNumber();
     uint32_t columnNumber = err->columnNumber();
     JSExnType errorType = err->type();
 
     // Create the Error object.
     return ErrorObject::create(cx, errorType, stack, fileName,
                                lineNumber, columnNumber, &copyReport, message);
 }
+
+JS_PUBLIC_API(bool)
+JS::CreateTypeError(JSContext *cx, HandleString stack, HandleString fileName,
+                    uint32_t lineNumber, uint32_t columnNumber, JSErrorReport *report,
+                    HandleString message, MutableHandleValue rval)
+{
+    assertSameCompartment(cx, stack, fileName, message);
+    js::ScopedJSFreePtr<JSErrorReport> rep;
+    if (report)
+        rep = CopyErrorReport(cx, report);
+
+    RootedObject obj(cx,
+        js::ErrorObject::create(cx, JSEXN_TYPEERR, stack, fileName,
+                                lineNumber, columnNumber, &rep, message));
+    if (!obj)
+        return false;
+
+    rval.setObject(*obj);
+    return true;
+}