mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Use GC-safe vector of JSFunction* to hold getters/setters.
This commit is contained in:
parent
661e422910
commit
2d8bdb7992
@ -73,7 +73,8 @@ namespace JSClasses {
|
|||||||
|
|
||||||
|
|
||||||
typedef std::pair<String, JSFunction*> MethodEntry;
|
typedef std::pair<String, JSFunction*> MethodEntry;
|
||||||
typedef std::vector<MethodEntry> JSMethods;
|
typedef std::vector<MethodEntry, gc_allocator<MethodEntry> > JSMethods;
|
||||||
|
typedef std::vector<JSFunction*, gc_allocator<JSFunction*> > JSFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a class in the JavaScript 2 (ECMA 4) language.
|
* Represents a class in the JavaScript 2 (ECMA 4) language.
|
||||||
@ -92,8 +93,8 @@ namespace JSClasses {
|
|||||||
JSMethods mMethods;
|
JSMethods mMethods;
|
||||||
bool mHasGetters; // tracks whether any getters/setters get assigned
|
bool mHasGetters; // tracks whether any getters/setters get assigned
|
||||||
bool mHasSetters;
|
bool mHasSetters;
|
||||||
JSFunction **mGetters; // allocated at 'complete()' time
|
JSFunctions mGetters; // allocated at 'complete()' time
|
||||||
JSFunction **mSetters;
|
JSFunctions mSetters;
|
||||||
public:
|
public:
|
||||||
JSClass(JSScope* scope, const String& name, JSClass* superClass = 0)
|
JSClass(JSScope* scope, const String& name, JSClass* superClass = 0)
|
||||||
: JSType(name, superClass),
|
: JSType(name, superClass),
|
||||||
@ -180,12 +181,12 @@ namespace JSClasses {
|
|||||||
|
|
||||||
bool hasGetter(uint32 index)
|
bool hasGetter(uint32 index)
|
||||||
{
|
{
|
||||||
return (mGetters && mGetters[index]);
|
return (index < mGetters.size() && mGetters[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasSetter(uint32 index)
|
bool hasSetter(uint32 index)
|
||||||
{
|
{
|
||||||
return (mSetters && mSetters[index]);
|
return (index < mSetters.size() && mSetters[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSFunction* getter(uint32 index)
|
JSFunction* getter(uint32 index)
|
||||||
@ -270,8 +271,8 @@ namespace JSClasses {
|
|||||||
bool complete()
|
bool complete()
|
||||||
{
|
{
|
||||||
if (mHasGetters || mHasSetters) {
|
if (mHasGetters || mHasSetters) {
|
||||||
if (mHasGetters) mGetters = new JSFunction*[mSlotCount];
|
if (mHasGetters) mGetters.resize(mSlotCount);
|
||||||
if (mHasSetters) mSetters = new JSFunction*[mSlotCount];
|
if (mHasSetters) mSetters.resize(mSlotCount);
|
||||||
JSSlots::iterator end = mSlots.end();
|
JSSlots::iterator end = mSlots.end();
|
||||||
for (JSSlots::iterator i = mSlots.begin(); i != end; i++) {
|
for (JSSlots::iterator i = mSlots.begin(); i != end; i++) {
|
||||||
if (mHasGetters) mGetters[i->second.mIndex] = i->second.mGetter;
|
if (mHasGetters) mGetters[i->second.mIndex] = i->second.mGetter;
|
||||||
|
@ -73,7 +73,8 @@ namespace JSClasses {
|
|||||||
|
|
||||||
|
|
||||||
typedef std::pair<String, JSFunction*> MethodEntry;
|
typedef std::pair<String, JSFunction*> MethodEntry;
|
||||||
typedef std::vector<MethodEntry> JSMethods;
|
typedef std::vector<MethodEntry, gc_allocator<MethodEntry> > JSMethods;
|
||||||
|
typedef std::vector<JSFunction*, gc_allocator<JSFunction*> > JSFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a class in the JavaScript 2 (ECMA 4) language.
|
* Represents a class in the JavaScript 2 (ECMA 4) language.
|
||||||
@ -92,8 +93,8 @@ namespace JSClasses {
|
|||||||
JSMethods mMethods;
|
JSMethods mMethods;
|
||||||
bool mHasGetters; // tracks whether any getters/setters get assigned
|
bool mHasGetters; // tracks whether any getters/setters get assigned
|
||||||
bool mHasSetters;
|
bool mHasSetters;
|
||||||
JSFunction **mGetters; // allocated at 'complete()' time
|
JSFunctions mGetters; // allocated at 'complete()' time
|
||||||
JSFunction **mSetters;
|
JSFunctions mSetters;
|
||||||
public:
|
public:
|
||||||
JSClass(JSScope* scope, const String& name, JSClass* superClass = 0)
|
JSClass(JSScope* scope, const String& name, JSClass* superClass = 0)
|
||||||
: JSType(name, superClass),
|
: JSType(name, superClass),
|
||||||
@ -180,12 +181,12 @@ namespace JSClasses {
|
|||||||
|
|
||||||
bool hasGetter(uint32 index)
|
bool hasGetter(uint32 index)
|
||||||
{
|
{
|
||||||
return (mGetters && mGetters[index]);
|
return (index < mGetters.size() && mGetters[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasSetter(uint32 index)
|
bool hasSetter(uint32 index)
|
||||||
{
|
{
|
||||||
return (mSetters && mSetters[index]);
|
return (index < mSetters.size() && mSetters[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSFunction* getter(uint32 index)
|
JSFunction* getter(uint32 index)
|
||||||
@ -270,8 +271,8 @@ namespace JSClasses {
|
|||||||
bool complete()
|
bool complete()
|
||||||
{
|
{
|
||||||
if (mHasGetters || mHasSetters) {
|
if (mHasGetters || mHasSetters) {
|
||||||
if (mHasGetters) mGetters = new JSFunction*[mSlotCount];
|
if (mHasGetters) mGetters.resize(mSlotCount);
|
||||||
if (mHasSetters) mSetters = new JSFunction*[mSlotCount];
|
if (mHasSetters) mSetters.resize(mSlotCount);
|
||||||
JSSlots::iterator end = mSlots.end();
|
JSSlots::iterator end = mSlots.end();
|
||||||
for (JSSlots::iterator i = mSlots.begin(); i != end; i++) {
|
for (JSSlots::iterator i = mSlots.begin(); i != end; i++) {
|
||||||
if (mHasGetters) mGetters[i->second.mIndex] = i->second.mGetter;
|
if (mHasGetters) mGetters[i->second.mIndex] = i->second.mGetter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user