Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ppapi/c/ppb_var.h

Issue 6673098: Remove PPB_Var interface's scripting functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing convert. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/c/ppb_class.h ('k') | ppapi/ppapi_cpp.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 #ifndef PPAPI_C_PPB_VAR_H_ 5 #ifndef PPAPI_C_PPB_VAR_H_
6 #define PPAPI_C_PPB_VAR_H_ 6 #define PPAPI_C_PPB_VAR_H_
7 7
8 #include "ppapi/c/pp_bool.h" 8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_macros.h" 10 #include "ppapi/c/pp_macros.h"
11 #include "ppapi/c/pp_module.h" 11 #include "ppapi/c/pp_module.h"
12 #include "ppapi/c/pp_resource.h" 12 #include "ppapi/c/pp_resource.h"
13 #include "ppapi/c/pp_stdint.h" 13 #include "ppapi/c/pp_stdint.h"
14 #include "ppapi/c/pp_var.h" 14 #include "ppapi/c/pp_var.h"
15 15
16 #define PPB_VAR_INTERFACE "PPB_Var;0.4" 16 #define PPB_VAR_INTERFACE "PPB_Var;0.5"
17 17
18 /** 18 /**
19 * @file 19 * @file
20 * This file defines the PPB_Var struct. 20 * This file defines the PPB_Var struct.
21 */ 21 */
22 22
23 /** 23 /**
24 *
25 * @addtogroup Enums
26 * @{
27 */
28
29 /**
30 * See http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript
31 * for general information on using this interface.
32 */
33 // PENDING: Should the generated doc really be pointing to methods?
34 enum PP_ObjectProperty_Modifier {
35 PP_OBJECTPROPERTY_MODIFIER_NONE = 0,
36 PP_OBJECTPROPERTY_MODIFIER_READONLY = 1 << 0,
37 PP_OBJECTPROPERTY_MODIFIER_DONTENUM = 1 << 1,
38 PP_OBJECTPROPERTY_MODIFIER_DONTDELETE = 1 << 2,
39 PP_OBJECTPROPERTY_MODIFIER_HASVALUE = 1 << 3
40 };
41 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(PP_ObjectProperty_Modifier, 4);
42 /**
43 * @}
44 */
45
46 /**
47 * @addtogroup Structs
48 * @{
49 */
50 struct PP_ObjectProperty {
51 struct PP_Var name;
52 struct PP_Var value;
53 struct PP_Var getter;
54 struct PP_Var setter;
55 uint32_t modifiers;
56
57 /** Ensure that this struct is 72 bytes wide by padding the end. In some
58 * compilers, PP_Var is 8-byte aligned, so those compilers align this struct
59 * on 8-byte boundaries as well and pad it to 72 bytes even without this
60 * padding attribute. This padding makes its size consistent across
61 * compilers.
62 */
63 int32_t padding;
64 };
65 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_ObjectProperty, 72);
66 /**
67 * @}
68 */
69
70 /**
71 * @addtogroup Interfaces 24 * @addtogroup Interfaces
72 * @{ 25 * @{
73 */ 26 */
74 27
75 /** 28 /**
76 * PPB_Var API 29 * PPB_Var API
77 *
78 * JavaScript specification:
79 *
80 * When referencing JS specification, we will refer to ECMAScript, 5th edition,
81 * and we will put section numbers in square brackets.
82 *
83 * Exception handling:
84 *
85 * If an exception parameter is NULL, then any exceptions that happen during the
86 * execution of the function will be ignored. If it is non-NULL, and has a type
87 * of PP_VARTYPE_UNDEFINED, then if an exception is thrown it will be stored in
88 * the exception variable. It it is non-NULL and not PP_VARTYPE_UNDEFINED, then
89 * the function is a no-op, and, if it returns a value, it will return
90 * PP_VARTYPE_UNDEFINED. This can be used to chain together multiple calls and
91 * only check the exception at the end.
92 *
93 * Make sure not to intermix non-JS with JS calls when relying on this behavior
94 * to catch JS exceptions, as non-JS functions will still execute!
95
96 * JS engine's exceptions will always be of type PP_VARTYPE_OBJECT. However,
97 * PP_Var interface can also throw PP_VARTYPE_STRING exceptions, in situations
98 * where there's no JS execution context defined. These are usually invalid
99 * parameter errors - passing an invalid PP_Var value, for example, will always
100 * result in an PP_VARTYPE_STRING exception. Exceptions will not be of any other
101 * type.
102 *
103 */ 30 */
104
105 // TODO(neb): Specify the exception for ill-formed PP_Vars, invalid module,
106 // instance, resource, string and object ids.
107 struct PPB_Var { 31 struct PPB_Var {
108 /** 32 /**
109 * Adds a reference to the given var. If this is not a refcounted object, 33 * Adds a reference to the given var. If this is not a refcounted object,
110 * this function will do nothing so you can always call it no matter what the 34 * this function will do nothing so you can always call it no matter what the
111 * type. 35 * type.
112 */ 36 */
113 void (*AddRef)(struct PP_Var var); 37 void (*AddRef)(struct PP_Var var);
114 38
115 /** 39 /**
116 * Removes a reference to given var, deleting it if the internal refcount 40 * Removes a reference to given var, deleting it if the internal refcount
(...skipping 29 matching lines...) Expand all
146 * be 0. 70 * be 0.
147 * 71 *
148 * If the var is not a string, this function will return NULL and |*len| will 72 * If the var is not a string, this function will return NULL and |*len| will
149 * be 0. 73 * be 0.
150 * 74 *
151 * The returned buffer will be valid as long as the underlying var is alive. 75 * The returned buffer will be valid as long as the underlying var is alive.
152 * If the plugin frees its reference, the string will be freed and the pointer 76 * If the plugin frees its reference, the string will be freed and the pointer
153 * will be to random memory. 77 * will be to random memory.
154 */ 78 */
155 const char* (*VarToUtf8)(struct PP_Var var, uint32_t* len); 79 const char* (*VarToUtf8)(struct PP_Var var, uint32_t* len);
156
157 /**
158 * Convert a variable to a different type using rules from ECMAScript
159 * specification, section [9].
160 *
161 * For conversions from/to PP_VARTYPE_OBJECT, the instance must be specified,
162 * or an exception of type PP_VARTYPE_STRING will be thrown.
163 */
164 struct PP_Var (*ConvertType)(PP_Instance instance,
165 struct PP_Var var,
166 PP_VarType new_type,
167 struct PP_Var* exception);
168
169 /**
170 * Sets a property on the object, similar to Object.prototype.defineProperty.
171 *
172 * First, if object is not PP_VARTYPE_OBJECT, throw an exception.
173 * Then, the property's 'name' field is converted to string using
174 * ConvertType (ToString [9.8]).
175 * After that, defineOwnProperty [8.12.9, 15.4.5.1] is called with the
176 * property.
177 * To set a simple property, set the value and set modifiers to default
178 * (Writable|Enumerable|Configurable|HasValue), see [8.12.15] and
179 * function PPB_MakeSimpleProperty.
180 */
181
182 // TODO(neb): Specify the exception. Ideally, it would be a TypeError, but
183 // don't have the JS context to create new objects, we might throw a string.
184 void (*DefineProperty)(struct PP_Var object,
185 struct PP_ObjectProperty property,
186 struct PP_Var* exception);
187
188 /**
189 * Tests whether an object has a property with a given name.
190 *
191 * First, if object is not PP_VARTYPE_OBJECT, throw an exception.
192 * Then, convert 'property' to string using ConvertType (ToString [9.8]).
193 * Then return true if the given property exists on the object [8.12.6].
194 */
195
196 // TODO(neb): Specify the exception. Ideally, it would be a TypeError, but
197 // don't have the JS context to create new objects, we might throw a string.
198 PP_Bool (*HasProperty)(struct PP_Var object,
199 struct PP_Var property,
200 struct PP_Var* exception);
201
202 /**
203 * Returns a given property of the object.
204 *
205 * First, if object is not PP_VARTYPE_OBJECT, throw an exception.
206 * Then, convert 'property' to string using ConvertType (ToString [9.8]).
207 * Then return the given property of the object [8.12.2].
208 */
209
210 // TODO(neb): Specify the exception. Ideally, it would be a TypeError, but
211 // don't have the JS context to create new objects, we might throw a string.
212 struct PP_Var (*GetProperty)(struct PP_Var object,
213 struct PP_Var property,
214 struct PP_Var* exception);
215
216 /**
217 * Delete a property from the object, return true if succeeded.
218 *
219 * True is returned if the property didn't exist in the first place.
220 *
221 * First, if object is not PP_VARTYPE_OBJECT, throw an exception.
222 * Then, convert 'property' to string using ConvertType (ToString [9.8]).
223 * Then delete the given property of the object [8.12.7].
224 */
225
226 // TODO(neb): Specify the exception. Ideally, it would be a TypeError, but
227 // don't have the JS context to create new objects, we might throw a string.
228 PP_Bool (*DeleteProperty)(struct PP_Var object,
229 struct PP_Var property,
230 struct PP_Var* exception);
231
232 /**
233 * Retrieves all property names on the given object. Property names include
234 * methods.
235 *
236 * If object is not PP_VARTYPE_OBJECT, throw an exception.
237 *
238 * If there is a failure, the given exception will be set (if it is non-NULL).
239 * On failure, |*properties| will be set to NULL and |*property_count| will be
240 * set to 0.
241 *
242 * A pointer to the array of property names will be placed in |*properties|.
243 * The caller is responsible for calling Release() on each of these properties
244 * (as per normal refcounted memory management) as well as freeing the array
245 * pointer with PPB_Core.MemFree().
246 *
247 * This function returns all "enumerable" properties. Some JavaScript
248 * properties are "hidden" and these properties won't be retrieved by this
249 * function, yet you can still set and get them. You can use JS
250 * Object.getOwnPropertyNames() to access these properties.
251 *
252 * Example:
253 * <pre> uint32_t count;
254 * PP_Var* properties;
255 * ppb_var.EnumerateProperties(object, &count, &properties);
256 *
257 * ...use the properties here...
258 *
259 * for (uint32_t i = 0; i < count; i++)
260 * ppb_var.Release(properties[i]);
261 * ppb_core.MemFree(properties); </pre>
262 */
263
264 // TODO(neb): Specify the exception. Ideally, it would be a TypeError, but
265 // don't have the JS context to create new objects, we might throw a string.
266 void (*EnumerateProperties)(struct PP_Var object,
267 uint32_t* property_count,
268 struct PP_Var** properties,
269 struct PP_Var* exception);
270
271 /**
272 * Check if an object is a JS Function [9.11].
273 */
274 PP_Bool (*IsCallable)(struct PP_Var object);
275
276 /**
277 * Call the functions.
278 *
279 * Similar to Function.prototype.call [15.3.4.4]. It will throw a TypeError
280 * and return undefined if object is not PP_VARTYPE_OBJECT, or is not
281 * callable.
282 *
283 * Pass the arguments to the function in order in the |argv| array, and the
284 * number of arguments in the |argc| parameter. |argv| can be NULL if |argc|
285 * is zero.
286 *
287 * Example:
288 * Call(obj.GetProperty("DoIt"), obj, 0, NULL, NULL)
289 * Equivalent to obj.DoIt() in JavaScript.
290 *
291 * Call(obj, PP_MakeUndefined(), 0, NULL, NULL)
292 * Equivalent to obj() in JavaScript.
293 */
294 struct PP_Var (*Call)(struct PP_Var object,
295 struct PP_Var this_object,
296 uint32_t argc,
297 struct PP_Var* argv,
298 struct PP_Var* exception);
299
300 /**
301 * Invoke the object as a constructor. It will throw a |TypeError| and return
302 * |undefined| if |object| is not PP_VARTYPE_OBJECT, or cannot be used as a
303 * constructor.
304 *
305 * Pass the arguments to the function in order in the |argv| array, and the
306 * number of arguments in the |argc| parameter. |argv| can be NULL if |argc|
307 * is zero.
308 *
309 * For example, if |object| is |String|, this is like saying |new String| in
310 * JavaScript. Similar to the [[Construct]] internal method [13.2.2].
311 *
312 * For examples, to construct an empty object, do:
313 * GetWindow().GetProperty("Object").Construct(0, NULL);
314 */
315 struct PP_Var (*Construct)(struct PP_Var object,
316 uint32_t argc,
317 struct PP_Var* argv,
318 struct PP_Var* exception);
319 }; 80 };
320 /** 81 /**
321 * @} 82 * @}
322 */ 83 */
323 84
324 /**
325 * @addtogroup Functions
326 * @{
327 */
328 PP_INLINE struct PP_ObjectProperty PP_MakeSimpleProperty(struct PP_Var name,
329 struct PP_Var value) {
330 struct PP_ObjectProperty result;
331 result.name = name;
332 result.value = value;
333 result.getter = PP_MakeUndefined();
334 result.setter = PP_MakeUndefined();
335 result.modifiers = PP_OBJECTPROPERTY_MODIFIER_HASVALUE;
336 return result;
337 }
338 /**
339 * @}
340 */
341
342 #endif /* PPAPI_C_PPB_VAR_H_ */ 85 #endif /* PPAPI_C_PPB_VAR_H_ */
343 86
OLDNEW
« no previous file with comments | « ppapi/c/ppb_class.h ('k') | ppapi/ppapi_cpp.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698