Bug 1071177 - Support symbol keys and throw exception on unique symbols with CPOWs. r=billm

This commit is contained in:
Tom Schuster 2014-10-16 18:39:38 +02:00
Родитель b19fa39e01
Коммит bfd10d6554
9 изменённых файлов: 36 добавлений и 26 удалений

Просмотреть файл

@ -12,6 +12,9 @@ var is_remote;
error_reporting_test(); error_reporting_test();
dom_test(); dom_test();
xray_test(); xray_test();
if (typeof Symbol === "function") {
symbol_test();
}
compartment_test(); compartment_test();
regexp_test(); regexp_test();
sync_test(); sync_test();
@ -119,15 +122,13 @@ function symbol_test()
{ {
let iterator = Symbol.iterator; let iterator = Symbol.iterator;
let named = Symbol.for("cpow-test"); let named = Symbol.for("cpow-test");
// let unique = Symbol();
let object = { let object = {
[iterator]: iterator, [iterator]: iterator,
[named]: named, [named]: named,
// [unique]: unique,
// "unique": unique
}; };
sendSyncMessage("cpows:symbol_test", {}, object); let test = ['a'];
sendSyncMessage("cpows:symbol_test", {}, {object: object, test: test});
} }
// Parent->Child references should go X->parent.privilegedJunkScope->child.privilegedJunkScope->Y // Parent->Child references should go X->parent.privilegedJunkScope->child.privilegedJunkScope->Y

Просмотреть файл

@ -206,10 +206,16 @@
} }
function recvSymbolTest(message) { function recvSymbolTest(message) {
let object = message.objects; let object = message.objects.object;
is(object[Symbol.iterator], Symbol.iterator, "Should use Symbol.iterator"); is(object[Symbol.iterator], Symbol.iterator, "Should use Symbol.iterator");
is(Symbol.keyFor(object[Symbol.for("cpow-test")]), "cpow-test", "Symbols aren't registered correctly"); is(Symbol.keyFor(object[Symbol.for("cpow-test")]), "cpow-test", "Symbols aren't registered correctly");
// is(object.unique, object[object.unique], "Unique symbols as ids and values don't seem to work"); let symbols = Object.getOwnPropertySymbols(object);
is(symbols.length, 2, "Object should have two symbol keys");
let test = undefined;
for (let x of message.objects.test) {
test = x;
}
is(test, "a", "for .. of iteration should work");
} }
let systemGlobal = this; let systemGlobal = this;
@ -307,7 +313,9 @@
mm.addMessageListener("cpows:dom_test", recvDomTest); mm.addMessageListener("cpows:dom_test", recvDomTest);
mm.addMessageListener("cpows:dom_test_after_gc", recvDomTestAfterGC); mm.addMessageListener("cpows:dom_test_after_gc", recvDomTestAfterGC);
mm.addMessageListener("cpows:xray_test", recvXrayTest); mm.addMessageListener("cpows:xray_test", recvXrayTest);
if (typeof Symbol === "function") {
mm.addMessageListener("cpows:symbol_test", recvSymbolTest); mm.addMessageListener("cpows:symbol_test", recvSymbolTest);
}
mm.addMessageListener("cpows:compartment_test", recvCompartmentTest); mm.addMessageListener("cpows:compartment_test", recvCompartmentTest);
mm.addMessageListener("cpows:regexp_test", recvRegExpTest); mm.addMessageListener("cpows:regexp_test", recvRegExpTest);
mm.addMessageListener("cpows:lifetime_test_1", recvLifetimeTest1); mm.addMessageListener("cpows:lifetime_test_1", recvLifetimeTest1);

Просмотреть файл

@ -102,8 +102,8 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
} }
bool RecvGetPropertyKeys(const uint64_t &objId, const uint32_t &flags, bool RecvGetPropertyKeys(const uint64_t &objId, const uint32_t &flags,
ReturnStatus *rs, nsTArray<nsString> *names) { ReturnStatus *rs, nsTArray<JSIDVariant> *ids) {
return Answer::RecvGetPropertyKeys(ObjectId::deserialize(objId), flags, rs, names); return Answer::RecvGetPropertyKeys(ObjectId::deserialize(objId), flags, rs, ids);
} }
bool RecvInstanceOf(const uint64_t &objId, const JSIID &iid, bool RecvInstanceOf(const uint64_t &objId, const JSIID &iid,
ReturnStatus *rs, bool *instanceof) { ReturnStatus *rs, bool *instanceof) {
@ -200,8 +200,8 @@ class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
} }
bool SendGetPropertyKeys(const ObjectId &objId, const uint32_t &flags, bool SendGetPropertyKeys(const ObjectId &objId, const uint32_t &flags,
ReturnStatus *rs, nsTArray<nsString> *names) { ReturnStatus *rs, nsTArray<JSIDVariant> *ids) {
return Base::SendGetPropertyKeys(objId.serialize(), flags, rs, names); return Base::SendGetPropertyKeys(objId.serialize(), flags, rs, ids);
} }
bool SendInstanceOf(const ObjectId &objId, const JSIID &iid, bool SendInstanceOf(const ObjectId &objId, const JSIID &iid,
ReturnStatus *rs, bool *instanceof) { ReturnStatus *rs, bool *instanceof) {

Просмотреть файл

@ -440,7 +440,8 @@ JavaScriptShared::toSymbolVariant(JSContext *cx, JS::Symbol *symArg, SymbolVaria
*symVarp = RegisteredSymbol(autoStr); *symVarp = RegisteredSymbol(autoStr);
return true; return true;
} }
MOZ_CRASH("unique symbols not yet implemented");
JS_ReportError(cx, "unique symbol can't be used with CPOW");
return false; return false;
} }

Просмотреть файл

@ -42,7 +42,7 @@ both:
prio(high) sync ClassName(uint64_t objId) returns (nsString name); prio(high) sync ClassName(uint64_t objId) returns (nsString name);
prio(high) sync RegExpToShared(uint64_t objId) returns (ReturnStatus rs, nsString source, uint32_t flags); prio(high) sync RegExpToShared(uint64_t objId) returns (ReturnStatus rs, nsString source, uint32_t flags);
prio(high) sync GetPropertyKeys(uint64_t objId, uint32_t flags) returns (ReturnStatus rs, nsString[] names); prio(high) sync GetPropertyKeys(uint64_t objId, uint32_t flags) returns (ReturnStatus rs, JSIDVariant[] ids);
prio(high) sync InstanceOf(uint64_t objId, JSIID iid) returns (ReturnStatus rs, bool instanceof); prio(high) sync InstanceOf(uint64_t objId, JSIID iid) returns (ReturnStatus rs, bool instanceof);
prio(high) sync DOMInstanceOf(uint64_t objId, int prototypeID, int depth) returns (ReturnStatus rs, bool instanceof); prio(high) sync DOMInstanceOf(uint64_t objId, int prototypeID, int depth) returns (ReturnStatus rs, bool instanceof);

Просмотреть файл

@ -580,7 +580,7 @@ WrapperAnswer::RecvRegExpToShared(const ObjectId &objId, ReturnStatus *rs,
bool bool
WrapperAnswer::RecvGetPropertyKeys(const ObjectId &objId, const uint32_t &flags, WrapperAnswer::RecvGetPropertyKeys(const ObjectId &objId, const uint32_t &flags,
ReturnStatus *rs, nsTArray<nsString> *names) ReturnStatus *rs, nsTArray<JSIDVariant> *ids)
{ {
AutoSafeJSContext cx; AutoSafeJSContext cx;
JSAutoRequest request(cx); JSAutoRequest request(cx);
@ -598,11 +598,11 @@ WrapperAnswer::RecvGetPropertyKeys(const ObjectId &objId, const uint32_t &flags,
return fail(cx, rs); return fail(cx, rs);
for (size_t i = 0; i < props.length(); i++) { for (size_t i = 0; i < props.length(); i++) {
nsString name; JSIDVariant id;
if (!convertIdToGeckoString(cx, props[i], &name)) if (!toJSIDVariant(cx, props[i], &id))
return fail(cx, rs); return fail(cx, rs);
names->AppendElement(name); ids->AppendElement(id);
} }
return ok(rs); return ok(rs);

Просмотреть файл

@ -55,7 +55,7 @@ class WrapperAnswer : public virtual JavaScriptShared
bool RecvRegExpToShared(const ObjectId &objId, ReturnStatus *rs, nsString *source, uint32_t *flags); bool RecvRegExpToShared(const ObjectId &objId, ReturnStatus *rs, nsString *source, uint32_t *flags);
bool RecvGetPropertyKeys(const ObjectId &objId, const uint32_t &flags, bool RecvGetPropertyKeys(const ObjectId &objId, const uint32_t &flags,
ReturnStatus *rs, nsTArray<nsString> *names); ReturnStatus *rs, nsTArray<JSIDVariant> *ids);
bool RecvInstanceOf(const ObjectId &objId, const JSIID &iid, bool RecvInstanceOf(const ObjectId &objId, const JSIID &iid,
ReturnStatus *rs, bool *instanceof); ReturnStatus *rs, bool *instanceof);
bool RecvDOMInstanceOf(const ObjectId &objId, const int &prototypeID, const int &depth, bool RecvDOMInstanceOf(const ObjectId &objId, const int &prototypeID, const int &depth,

Просмотреть файл

@ -232,7 +232,7 @@ CPOWProxyHandler::ownPropertyKeys(JSContext *cx, HandleObject proxy,
bool bool
WrapperOwner::ownPropertyKeys(JSContext *cx, HandleObject proxy, AutoIdVector &props) WrapperOwner::ownPropertyKeys(JSContext *cx, HandleObject proxy, AutoIdVector &props)
{ {
return getPropertyKeys(cx, proxy, JSITER_OWNONLY | JSITER_HIDDEN, props); return getPropertyKeys(cx, proxy, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
} }
bool bool
@ -776,8 +776,8 @@ WrapperOwner::getPropertyKeys(JSContext *cx, HandleObject proxy, uint32_t flags,
ObjectId objId = idOf(proxy); ObjectId objId = idOf(proxy);
ReturnStatus status; ReturnStatus status;
InfallibleTArray<nsString> names; InfallibleTArray<JSIDVariant> ids;
if (!SendGetPropertyKeys(objId, flags, &status, &names)) if (!SendGetPropertyKeys(objId, flags, &status, &ids))
return ipcfail(cx); return ipcfail(cx);
LOG_STACK(); LOG_STACK();
@ -785,11 +785,11 @@ WrapperOwner::getPropertyKeys(JSContext *cx, HandleObject proxy, uint32_t flags,
if (!ok(cx, status)) if (!ok(cx, status))
return false; return false;
for (size_t i = 0; i < names.Length(); i++) { for (size_t i = 0; i < ids.Length(); i++) {
RootedId name(cx); RootedId id(cx);
if (!convertGeckoStringToId(cx, names[i], &name)) if (!fromJSIDVariant(cx, ids[i], &id))
return false; return false;
if (!props.append(name)) if (!props.append(id))
return false; return false;
} }

Просмотреть файл

@ -146,7 +146,7 @@ class WrapperOwner : public virtual JavaScriptShared
uint32_t *flags) = 0; uint32_t *flags) = 0;
virtual bool SendGetPropertyKeys(const ObjectId &objId, const uint32_t &flags, virtual bool SendGetPropertyKeys(const ObjectId &objId, const uint32_t &flags,
ReturnStatus *rs, nsTArray<nsString> *names) = 0; ReturnStatus *rs, nsTArray<JSIDVariant> *ids) = 0;
virtual bool SendInstanceOf(const ObjectId &objId, const JSIID &iid, virtual bool SendInstanceOf(const ObjectId &objId, const JSIID &iid,
ReturnStatus *rs, bool *instanceof) = 0; ReturnStatus *rs, bool *instanceof) = 0;
virtual bool SendDOMInstanceOf(const ObjectId &objId, const int &prototypeID, const int &depth, virtual bool SendDOMInstanceOf(const ObjectId &objId, const int &prototypeID, const int &depth,