Bug 675884 - Implement Event constructors, part2, r=jst
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 14 Dec 2011 21:54:46 +0200
changeset 82580 1ab5ed4f93bf3d395c025ea387858c21c4eb0bf4
parent 82579 01a26239462a99c30b0b153f128db081a959845a
child 82581 141ae3a6ccd2dd8074ef3174e791f2831bb86d80
push id21672
push useropettay@mozilla.com
push dateWed, 14 Dec 2011 20:37:16 +0000
treeherdermozilla-central@0507a68e994b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs675884
milestone11.0a1
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
Bug 675884 - Implement Event constructors, part2, r=jst
content/events/src/nsDOMEvent.cpp
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -56,16 +56,17 @@
 #include "nsGkAtoms.h"
 #include "nsMutationEvent.h"
 #include "nsContentUtils.h"
 #include "nsIURI.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIScriptError.h"
 #include "nsDOMPopStateEvent.h"
 #include "mozilla/Preferences.h"
+#include "nsJSUtils.h"
 
 using namespace mozilla;
 
 static const char* const sEventNames[] = {
   "mousedown", "mouseup", "click", "dblclick", "mouseenter", "mouseleave", "mouseover",
   "mouseout", "MozMouseHittest", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
   "focus", "blur", "load", "popstate", "beforescriptexecute",
   "afterscriptexecute", "beforeunload", "unload",
@@ -400,25 +401,19 @@ nsDOMEvent::Initialize(nsISupports* aOwn
 
   JSAutoRequest ar(aCx);
   JSString* jsstr = JS_ValueToString(aCx, aArgv[0]);
   if (!jsstr) {
     return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   JS::Anchor<JSString*> deleteProtector(jsstr);
-  size_t length;
-  const jschar* chars = JS_GetStringCharsAndLength(aCx, jsstr, &length);
-  if (!chars) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
-  nsAutoString type;
-  type.Assign(chars, length);
-  deleteProtector.clear();
+  nsDependentJSString type;
+  NS_ENSURE_STATE(type.init(aCx, jsstr));
   
   nsCOMPtr<nsISupports> dict;
   if (aArgc >= 2 && !JSVAL_IS_PRIMITIVE(aArgv[1])) {
     nsContentUtils::XPConnect()->WrapJS(aCx, JSVAL_TO_OBJECT(aArgv[1]),
                                         EventInitIID(),
                                         getter_AddRefs(dict));
   }
   nsresult rv = InitFromCtor(type, dict);