зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1289951 - Add mozIntl toolkit component. r=waldo
MozReview-Commit-ID: J34WJ9o1BKI
This commit is contained in:
Родитель
3a45d46820
Коммит
b9edbd29bd
|
@ -264,6 +264,7 @@
|
||||||
@RESPATH@/browser/components/migration.xpt
|
@RESPATH@/browser/components/migration.xpt
|
||||||
@RESPATH@/components/mimetype.xpt
|
@RESPATH@/components/mimetype.xpt
|
||||||
@RESPATH@/components/mozfind.xpt
|
@RESPATH@/components/mozfind.xpt
|
||||||
|
@RESPATH@/components/mozintl.xpt
|
||||||
@RESPATH@/components/necko_about.xpt
|
@RESPATH@/components/necko_about.xpt
|
||||||
@RESPATH@/components/necko_cache.xpt
|
@RESPATH@/components/necko_cache.xpt
|
||||||
@RESPATH@/components/necko_cache2.xpt
|
@RESPATH@/components/necko_cache2.xpt
|
||||||
|
|
|
@ -36,6 +36,7 @@ DIRS += [
|
||||||
'lz4',
|
'lz4',
|
||||||
'mediasniffer',
|
'mediasniffer',
|
||||||
'microformats',
|
'microformats',
|
||||||
|
'mozintl',
|
||||||
'osfile',
|
'osfile',
|
||||||
'parentalcontrols',
|
'parentalcontrols',
|
||||||
'passwordmgr',
|
'passwordmgr',
|
||||||
|
|
|
@ -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;
|
|
@ -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
|
|
@ -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'
|
|
@ -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);
|
||||||
|
};
|
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
[DEFAULT]
|
||||||
|
head =
|
||||||
|
tail =
|
||||||
|
|
||||||
|
[test_mozintl.js]
|
Загрузка…
Ссылка в новой задаче