summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/API/JSCallbackObject.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/API/JSCallbackObject.h')
-rw-r--r--Source/JavaScriptCore/API/JSCallbackObject.h68
1 files changed, 43 insertions, 25 deletions
diff --git a/Source/JavaScriptCore/API/JSCallbackObject.h b/Source/JavaScriptCore/API/JSCallbackObject.h
index 3f58906d9..43749e258 100644
--- a/Source/JavaScriptCore/API/JSCallbackObject.h
+++ b/Source/JavaScriptCore/API/JSCallbackObject.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2016 Apple Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -30,11 +30,12 @@
#include "JSObjectRef.h"
#include "JSValueRef.h"
#include "JSObject.h"
-#include <wtf/PassOwnPtr.h>
namespace JSC {
-struct JSCallbackObjectData : WeakHandleOwner {
+struct JSCallbackObjectData {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
JSCallbackObjectData(void* privateData, JSClassRef jsClass)
: privateData(privateData)
, jsClass(jsClass)
@@ -42,7 +43,7 @@ struct JSCallbackObjectData : WeakHandleOwner {
JSClassRetain(jsClass);
}
- virtual ~JSCallbackObjectData()
+ ~JSCallbackObjectData()
{
JSClassRelease(jsClass);
}
@@ -57,7 +58,7 @@ struct JSCallbackObjectData : WeakHandleOwner {
void setPrivateProperty(VM& vm, JSCell* owner, const Identifier& propertyName, JSValue value)
{
if (!m_privateProperties)
- m_privateProperties = adoptPtr(new JSPrivatePropertyMap);
+ m_privateProperties = std::make_unique<JSPrivatePropertyMap>();
m_privateProperties->setPrivateProperty(vm, owner, propertyName, value);
}
@@ -70,14 +71,17 @@ struct JSCallbackObjectData : WeakHandleOwner {
void visitChildren(SlotVisitor& visitor)
{
- if (!m_privateProperties)
+ JSPrivatePropertyMap* properties = m_privateProperties.get();
+ if (!properties)
return;
- m_privateProperties->visitChildren(visitor);
+ properties->visitChildren(visitor);
}
void* privateData;
JSClassRef jsClass;
struct JSPrivatePropertyMap {
+ WTF_MAKE_FAST_ALLOCATED;
+ public:
JSValue getPrivateProperty(const Identifier& propertyName) const
{
PrivatePropertyMap::const_iterator location = m_propertyMap.find(propertyName.impl());
@@ -88,29 +92,32 @@ struct JSCallbackObjectData : WeakHandleOwner {
void setPrivateProperty(VM& vm, JSCell* owner, const Identifier& propertyName, JSValue value)
{
+ LockHolder locker(m_lock);
WriteBarrier<Unknown> empty;
m_propertyMap.add(propertyName.impl(), empty).iterator->value.set(vm, owner, value);
}
void deletePrivateProperty(const Identifier& propertyName)
{
+ LockHolder locker(m_lock);
m_propertyMap.remove(propertyName.impl());
}
void visitChildren(SlotVisitor& visitor)
{
- for (PrivatePropertyMap::iterator ptr = m_propertyMap.begin(); ptr != m_propertyMap.end(); ++ptr) {
- if (ptr->value)
- visitor.append(&ptr->value);
+ LockHolder locker(m_lock);
+ for (auto& pair : m_propertyMap) {
+ if (pair.value)
+ visitor.append(pair.value);
}
}
private:
- typedef HashMap<RefPtr<StringImpl>, WriteBarrier<Unknown>, IdentifierRepHash> PrivatePropertyMap;
+ typedef HashMap<RefPtr<UniquedStringImpl>, WriteBarrier<Unknown>, IdentifierRepHash> PrivatePropertyMap;
PrivatePropertyMap m_propertyMap;
+ Lock m_lock;
};
- OwnPtr<JSPrivatePropertyMap> m_privateProperties;
- virtual void finalize(Handle<Unknown>, void*) override;
+ std::unique_ptr<JSPrivatePropertyMap> m_privateProperties;
};
@@ -125,6 +132,9 @@ protected:
public:
typedef Parent Base;
+ static const unsigned StructureFlags = Base::StructureFlags | ProhibitsPropertyCaching | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | ImplementsHasInstance | OverridesGetPropertyNames | TypeOfShouldCallGetCallData;
+
+ ~JSCallbackObject();
static JSCallbackObject* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSClassRef classRef, void* data)
{
@@ -144,7 +154,19 @@ public:
void setPrivate(void* data);
void* getPrivate();
+ // FIXME: We should fix the warnings for extern-template in JSObject template classes: https://bugs.webkit.org/show_bug.cgi?id=161979
+#if COMPILER(CLANG)
+#if __has_warning("-Wundefined-var-template")
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wundefined-var-template"
+#endif
+#endif
DECLARE_INFO;
+#if COMPILER(CLANG)
+#if __has_warning("-Wundefined-var-template")
+#pragma clang diagnostic pop
+#endif
+#endif
JSClassRef classRef() const { return m_callbackObjectData->jsClass; }
bool inherits(JSClassRef) const;
@@ -168,9 +190,6 @@ public:
using Parent::methodTable;
-protected:
- static const unsigned StructureFlags = ProhibitsPropertyCaching | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | ImplementsHasInstance | OverridesHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | Parent::StructureFlags;
-
private:
static String className(const JSObject*);
@@ -179,8 +198,8 @@ private:
static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
- static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
- static void putByIndex(JSCell*, ExecState*, unsigned, JSValue, bool shouldThrow);
+ static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
+ static bool putByIndex(JSCell*, ExecState*, unsigned, JSValue, bool shouldThrow);
static bool deleteProperty(JSCell*, ExecState*, PropertyName);
static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned);
@@ -196,8 +215,6 @@ private:
{
JSCallbackObject* thisObject = jsCast<JSCallbackObject*>(cell);
ASSERT_GC_OBJECT_INHERITS((static_cast<Parent*>(thisObject)), JSCallbackObject<Parent>::info());
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->Parent::structure()->typeInfo().overridesVisitChildren());
Parent::visitChildren(thisObject, visitor);
thisObject->m_callbackObjectData->visitChildren(visitor);
}
@@ -211,10 +228,11 @@ private:
static EncodedJSValue JSC_HOST_CALL construct(ExecState*);
JSValue getStaticValue(ExecState*, PropertyName);
- static EncodedJSValue staticFunctionGetter(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
- static EncodedJSValue callbackGetter(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+ static EncodedJSValue staticFunctionGetter(ExecState*, EncodedJSValue, PropertyName);
+ static EncodedJSValue callbackGetter(ExecState*, EncodedJSValue, PropertyName);
- OwnPtr<JSCallbackObjectData> m_callbackObjectData;
+ std::unique_ptr<JSCallbackObjectData> m_callbackObjectData;
+ const ClassInfo* m_classInfo;
};
} // namespace JSC