SpiderMonkey 38 removes the JS_LookupProperty{,ById} API. Refs #3708.
Use JS_GetProperty{,ById} instead.
Ensure that we break if someone tries to serialize a getter by using
something similar to what we used pre 47a03c3397
.
https://bugzilla.mozilla.org/show_bug.cgi?id=1094176
This was SVN commit r17633.
This commit is contained in:
parent
39eb7fb243
commit
f4898c18d8
@ -179,8 +179,8 @@ void CBinarySerializerScriptImpl::HandleScriptVal(JS::HandleValue val)
|
||||
if (hasCustomSerialize)
|
||||
{
|
||||
JS::RootedValue serialize(cx);
|
||||
if (!JS_LookupProperty(cx, obj, "Serialize", &serialize))
|
||||
throw PSERROR_Serialize_ScriptError("JS_LookupProperty failed");
|
||||
if (!JS_GetProperty(cx, obj, "Serialize", &serialize))
|
||||
throw PSERROR_Serialize_ScriptError("JS_GetProperty failed");
|
||||
|
||||
// If serialize is null, so don't serialize anything more
|
||||
if (!serialize.isNull())
|
||||
@ -312,7 +312,14 @@ void CBinarySerializerScriptImpl::HandleScriptVal(JS::HandleValue val)
|
||||
|
||||
JS::RootedValue idval(cx);
|
||||
JS::RootedValue propval(cx);
|
||||
|
||||
|
||||
// Forbid getters, which might delete values and mess things up.
|
||||
JS::Rooted<JSPropertyDescriptor> desc(cx);
|
||||
if (!JS_GetPropertyDescriptorById(cx, obj, id, &desc))
|
||||
throw PSERROR_Serialize_ScriptError("JS_GetPropertyDescriptorById failed");
|
||||
if (desc.hasGetterObject())
|
||||
throw PSERROR_Serialize_ScriptError("Cannot serialize property getters");
|
||||
|
||||
// Get the property name as a string
|
||||
if (!JS_IdToValue(cx, id, &idval))
|
||||
throw PSERROR_Serialize_ScriptError("JS_IdToValue failed");
|
||||
@ -322,10 +329,8 @@ void CBinarySerializerScriptImpl::HandleScriptVal(JS::HandleValue val)
|
||||
|
||||
ScriptString("prop name", idstr);
|
||||
|
||||
// Use LookupProperty instead of GetProperty to avoid the danger of getters
|
||||
// (they might delete values and trigger GC)
|
||||
if (!JS_LookupPropertyById(cx, obj, id, &propval))
|
||||
throw PSERROR_Serialize_ScriptError("JS_LookupPropertyById failed");
|
||||
if (!JS_GetPropertyById(cx, obj, id, &propval))
|
||||
throw PSERROR_Serialize_ScriptError("JS_GetPropertyById failed");
|
||||
|
||||
HandleScriptVal(propval);
|
||||
}
|
||||
|
@ -202,8 +202,8 @@ jsval CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleObject
|
||||
if (hasCustomDeserialize)
|
||||
{
|
||||
JS::RootedValue serialize(cx);
|
||||
if (!JS_LookupProperty(cx, obj, "Serialize", &serialize))
|
||||
throw PSERROR_Serialize_ScriptError("JS_LookupProperty failed");
|
||||
if (!JS_GetProperty(cx, obj, "Serialize", &serialize))
|
||||
throw PSERROR_Serialize_ScriptError("JS_GetProperty failed");
|
||||
bool hasNullSerialize = hasCustomSerialize && serialize.isNull();
|
||||
|
||||
// If Serialize is null, we'll still call Deserialize but with undefined argument
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2016 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -789,7 +789,7 @@ entities:\n\
|
||||
man.AddComponent(hnd1, man.LookupCID("TestScript1_getter"), noParam);
|
||||
|
||||
std::stringstream stateStream;
|
||||
TS_ASSERT(man.SerializeState(stateStream));
|
||||
TS_ASSERT_THROWS_PSERROR(man.SerializeState(stateStream), PSERROR_Serialize_ScriptError, "Cannot serialize property getters");
|
||||
// (The script will die if the getter is executed)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user