Bug 1017302 - Expose add-on IDs to JS engine (r=bholley)
authorBill McCloskey <wmccloskey@mozilla.com>
Sat, 21 Jun 2014 11:54:22 -0700
changeset 189915 59d1fd1d1391789cbd2d8a238aabc98dcdadacd2
parent 189914 efc771d4648c4e8388f9e99ee8508abbd788e750
child 189916 a0265bd71a156961e87f9f3a99763067ce1b577c
push id45197
push userwmccloskey@mozilla.com
push dateSat, 21 Jun 2014 18:56:00 +0000
treeherdermozilla-inbound@53bfc7d49029 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1017302
milestone33.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 1017302 - Expose add-on IDs to JS engine (r=bholley)
js/public/TypeDecls.h
js/src/jsapi.cpp
js/src/jsapi.h
js/src/vm/String.h
--- a/js/public/TypeDecls.h
+++ b/js/public/TypeDecls.h
@@ -22,16 +22,17 @@
 
 #include "js-config.h"
 
 struct JSContext;
 class JSFunction;
 class JSObject;
 class JSScript;
 class JSString;
+class JSAddonId;
 
 struct jsid;
 
 typedef char16_t jschar;
 
 namespace JS {
 
 typedef unsigned char Latin1Char;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1002,16 +1002,34 @@ JS_SetCompartmentPrivate(JSCompartment *
 }
 
 JS_PUBLIC_API(void *)
 JS_GetCompartmentPrivate(JSCompartment *compartment)
 {
     return compartment->data;
 }
 
+JS_PUBLIC_API(JSAddonId *)
+JS::NewAddonId(JSContext *cx, HandleString str)
+{
+    return static_cast<JSAddonId *>(JS_InternJSString(cx, str));
+}
+
+JS_PUBLIC_API(const jschar *)
+JS::CharsZOfAddonId(JSAddonId *id)
+{
+    return id->charsZ();
+}
+
+JS_PUBLIC_API(JSString *)
+JS::StringOfAddonId(JSAddonId *id)
+{
+    return id;
+}
+
 JS_PUBLIC_API(void)
 JS_SetZoneUserData(JS::Zone *zone, void *data)
 {
     zone->data = data;
 }
 
 JS_PUBLIC_API(void *)
 JS_GetZoneUserData(JS::Zone *zone)
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4319,16 +4319,29 @@ class JSAutoByteString
     char        *mBytes;
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 
     /* Copy and assignment are not supported. */
     JSAutoByteString(const JSAutoByteString &another);
     JSAutoByteString &operator=(const JSAutoByteString &another);
 };
 
+namespace JS {
+
+extern JS_PUBLIC_API(JSAddonId *)
+NewAddonId(JSContext *cx, JS::HandleString str);
+
+extern JS_PUBLIC_API(const jschar *)
+CharsZOfAddonId(JSAddonId *id);
+
+extern JS_PUBLIC_API(JSString *)
+StringOfAddonId(JSAddonId *id);
+
+} // namespace JS
+
 /************************************************************************/
 /*
  * JSON functions
  */
 typedef bool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data);
 
 /*
  * JSON.stringify as specified by ES5.
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -1273,16 +1273,21 @@ class AutoNameVector : public AutoVector
 };
 
 template <typename CharT>
 void
 CopyChars(CharT *dest, const JSLinearString &str);
 
 } /* namespace js */
 
+// Addon IDs are interned atoms which are never destroyed. This detail is
+// not exposed outside the API.
+class JSAddonId : public JSAtom
+{};
+
 /* Avoid requiring vm/String-inl.h just to call getChars. */
 
 MOZ_ALWAYS_INLINE const jschar *
 JSString::getChars(js::ExclusiveContext *cx)
 {
     if (JSLinearString *str = ensureLinear(cx))
         return str->chars();
     return nullptr;