OSDN Git Service

Merge WebKit at r60074: Initial merge by git
[android-x86/external-webkit.git] / JavaScriptCore / API / JSWeakObjectMapRefPrivate.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef JSWeakObjectMapRefPrivate_h
27 #define JSWeakObjectMapRefPrivate_h
28
29 #include <JavaScriptCore/JSContextRef.h>
30 #include <JavaScriptCore/JSValueRef.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35     
36 /*! @typedef JSWeakObjectMapRef A weak map for storing JSObjectRefs */
37 typedef struct OpaqueJSWeakObjectMap* JSWeakObjectMapRef;
38
39 /*! 
40  @typedef JSWeakMapDestroyedCallback
41  @abstract The callback invoked when a JSWeakObjectMapRef is being destroyed.
42  @param map The map that is being destroyed.
43  @param data The private data (if any) that was associated with the map instance.
44  */
45 typedef void (*JSWeakMapDestroyedCallback)(JSWeakObjectMapRef map, void* data);
46
47 /*!
48  @function
49  @abstract Creates a weak value map that can be used to reference user defined objects without preventing them from being collected.
50  @param ctx The execution context to use.
51  @param data A void* to set as the map's private data. Pass NULL to specify no private data.
52  @param destructor A function to call when the weak map is destroyed.
53  @result A JSWeakObjectMapRef bound to the given context, data and destructor.
54  @discussion The JSWeakObjectMapRef can be used as a storage mechanism to hold custom JS objects without forcing those objects to
55  remain live as JSValueProtect would.  Any objects that are intended to be stored in a weak map must be user defined objects that
56  remove themselves from the map in their finalizer.
57  */
58 JS_EXPORT JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef ctx, void* data, JSWeakMapDestroyedCallback destructor);
59
60 /*!
61  @function
62  @abstract Associates a JSObjectRef with the given key in a JSWeakObjectMap.
63  @param ctx The execution context to use.
64  @param map The map to operate on.
65  @param key The key to associate a weak reference with.
66  @param object The user defined object to associate with the key.
67  */
68 JS_EXPORT void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef);
69
70 /*!
71  @function
72  @abstract Retrieves the JSObjectRef associated with a key.
73  @param ctx The execution context to use.
74  @param map The map to query.
75  @param key The key to search for.
76  @result Either the live object associated with the provided key, or NULL.
77  */
78 JS_EXPORT JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key);
79
80 /*!
81  @function
82  @abstract Clears the association between a key and an object in a JSWeakObjectMapRef
83  @param ctx The execution context to use.
84  @param map The map to clear the key association from.
85  @param key The key to use.
86  @param object The old object value.
87  @result Returns true if the key/object association was present in map, and has been removed.
88  */
89 JS_EXPORT bool JSWeakObjectMapClear(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object);
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif // JSWeakObjectMapPrivate_h