Bug 1289951 - Add mozIntl toolkit component. r=waldo
☠☠ backed out by 02c88cba5572 ☠ ☠
authorZibi Braniecki <gandalf@mozilla.com>
Thu, 01 Sep 2016 21:28:44 +0200
changeset 312346 1ac6a04f5bc7afb0a44410497e944d7a2b95cd81
parent 312345 488c4013ece13ea7ae090e6b9a8cd279405e14dd
child 312347 eb8541ab49c447041c2444b13d6d9afa4c1fdc64
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1289951
milestone51.0a1
Bug 1289951 - Add mozIntl toolkit component. r=waldo MozReview-Commit-ID: IVrrDSfGY4R
toolkit/components/moz.build
toolkit/components/mozintl/MozIntl.cpp
toolkit/components/mozintl/MozIntl.h
toolkit/components/mozintl/moz.build
toolkit/components/mozintl/mozIMozIntl.idl
toolkit/components/mozintl/test/test_mozintl.js
toolkit/components/mozintl/test/xpcshell.ini
--- a/toolkit/components/moz.build
+++ b/toolkit/components/moz.build
@@ -31,16 +31,17 @@ DIRS += [
     'finalizationwitness',
     'formautofill',
     'find',
     'gfx',
     'jsdownloads',
     'lz4',
     'mediasniffer',
     'microformats',
+    'mozintl',
     'osfile',
     'parentalcontrols',
     'passwordmgr',
     'perf',
     'perfmonitoring',
     'places',
     'privatebrowsing',
     'processsingleton',
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/MozIntl.cpp
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "MozIntl.h"
+#include "jswrapper.h"
+#include "mozilla/ModuleUtils.h"
+
+#define MOZ_MOZINTL_CID \
+  { 0x83f8f991, 0x6b81, 0x4dd8, { 0xa0, 0x93, 0x72, 0x0b, 0xfb, 0x67, 0x4d, 0x38 } }
+
+using namespace mozilla;
+
+NS_IMPL_ISUPPORTS(MozIntl, mozIMozIntl)
+
+MozIntl::MozIntl()
+{
+}
+
+MozIntl::~MozIntl()
+{
+}
+
+NS_IMETHODIMP
+MozIntl::AddGetCalendarInfo(JS::Handle<JS::Value> val, JSContext* cx)
+{
+  if (!val.isObject()) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  JS::Rooted<JSObject*> realIntlObj(cx, js::CheckedUnwrap(&val.toObject()));
+  if (!realIntlObj) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  JSAutoCompartment ac(cx, realIntlObj);
+
+  static const JSFunctionSpec funcs[] = {
+    JS_SELF_HOSTED_FN("getCalendarInfo", "Intl_getCalendarInfo", 1, 0),
+    JS_FS_END
+  };
+
+  if (!JS_DefineFunctions(cx, realIntlObj, funcs)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return NS_OK;
+}
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(MozIntl)
+NS_DEFINE_NAMED_CID(MOZ_MOZINTL_CID);
+
+static const Module::CIDEntry kMozIntlCIDs[] = {
+  { &kMOZ_MOZINTL_CID, false, nullptr, MozIntlConstructor },
+  { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kMozIntlContracts[] = {
+  { "@mozilla.org/mozintl;1", &kMOZ_MOZINTL_CID },
+  { nullptr }
+};
+
+static const mozilla::Module kMozIntlModule = {
+  mozilla::Module::kVersion,
+  kMozIntlCIDs,
+  kMozIntlContracts,
+  nullptr,
+  nullptr,
+  nullptr,
+  nullptr
+};
+
+NSMODULE_DEFN(mozMozIntlModule) = &kMozIntlModule;
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/MozIntl.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozIMozIntl.h"
+
+namespace mozilla {
+
+class MozIntl final : public mozIMozIntl
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_MOZIMOZINTL
+
+  MozIntl();
+
+private:
+  ~MozIntl();
+};
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/moz.build
@@ -0,0 +1,19 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
+
+XPIDL_SOURCES += [
+    'mozIMozIntl.idl',
+]
+
+XPIDL_MODULE = 'mozintl'
+
+SOURCES += [
+    'MozIntl.cpp',
+]
+
+FINAL_LIBRARY = 'xul'
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/mozIMozIntl.idl
@@ -0,0 +1,12 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(9f9bc42e-54f4-11e6-9aed-4b1429ac0ba0)]
+interface mozIMozIntl : nsISupports
+{
+  [implicit_jscontext] void addGetCalendarInfo(in jsval intlObject);
+};
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/test/test_mozintl.js
@@ -0,0 +1,32 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+  const mozIntl = Components.classes["@mozilla.org/mozintl;1"]
+                            .getService(Components.interfaces.mozIMozIntl);
+
+  test_this_global(mozIntl);
+  test_cross_global(mozIntl);
+
+  ok(true);
+}
+
+function test_this_global(mozIntl) {
+  let x = {};
+
+  mozIntl.addGetCalendarInfo(x);
+  equal(x.getCalendarInfo instanceof Function, true);
+  equal(x.getCalendarInfo() instanceof Object, true);
+}
+
+function test_cross_global(mozIntl) {
+  var global = new Components.utils.Sandbox("https://example.com/");
+  var x = global.Object();
+
+  mozIntl.addGetCalendarInfo(x);
+  var waivedX = Components.utils.waiveXrays(x);
+  equal(waivedX.getCalendarInfo instanceof Function, false);
+  equal(waivedX.getCalendarInfo instanceof global.Function, true);
+  equal(waivedX.getCalendarInfo() instanceof Object, false);
+  equal(waivedX.getCalendarInfo() instanceof global.Object, true);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mozintl/test/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+head =
+tail =
+
+[test_mozintl.js]