diff options
Diffstat (limited to 'toolkit/components/mozintl')
-rw-r--r-- | toolkit/components/mozintl/MozIntl.cpp | 74 | ||||
-rw-r--r-- | toolkit/components/mozintl/MozIntl.h | 22 | ||||
-rw-r--r-- | toolkit/components/mozintl/moz.build | 19 | ||||
-rw-r--r-- | toolkit/components/mozintl/mozIMozIntl.idl | 12 | ||||
-rw-r--r-- | toolkit/components/mozintl/test/test_mozintl.js | 32 | ||||
-rw-r--r-- | toolkit/components/mozintl/test/xpcshell.ini | 5 |
6 files changed, 164 insertions, 0 deletions
diff --git a/toolkit/components/mozintl/MozIntl.cpp b/toolkit/components/mozintl/MozIntl.cpp new file mode 100644 index 000000000..9c393c296 --- /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; diff --git a/toolkit/components/mozintl/MozIntl.h b/toolkit/components/mozintl/MozIntl.h new file mode 100644 index 000000000..00c10ed19 --- /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 diff --git a/toolkit/components/mozintl/moz.build b/toolkit/components/mozintl/moz.build new file mode 100644 index 000000000..a92ed50b7 --- /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' diff --git a/toolkit/components/mozintl/mozIMozIntl.idl b/toolkit/components/mozintl/mozIMozIntl.idl new file mode 100644 index 000000000..67be184d4 --- /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); +}; diff --git a/toolkit/components/mozintl/test/test_mozintl.js b/toolkit/components/mozintl/test/test_mozintl.js new file mode 100644 index 000000000..0eca2c67e --- /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); +} diff --git a/toolkit/components/mozintl/test/xpcshell.ini b/toolkit/components/mozintl/test/xpcshell.ini new file mode 100644 index 000000000..8fecd3933 --- /dev/null +++ b/toolkit/components/mozintl/test/xpcshell.ini @@ -0,0 +1,5 @@ +[DEFAULT] +head = +tail = + +[test_mozintl.js] |