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

Side by Side Diff: include/v8.h

Issue 660243: Small API improvements: (Closed)
Patch Set: Created 10 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
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/runtime.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 template <class S> static inline Handle<T> Cast(Handle<S> that) { 255 template <class S> static inline Handle<T> Cast(Handle<S> that) {
256 #ifdef V8_ENABLE_CHECKS 256 #ifdef V8_ENABLE_CHECKS
257 // If we're going to perform the type check then we have to check 257 // If we're going to perform the type check then we have to check
258 // that the handle isn't empty before doing the checked cast. 258 // that the handle isn't empty before doing the checked cast.
259 if (that.IsEmpty()) return Handle<T>(); 259 if (that.IsEmpty()) return Handle<T>();
260 #endif 260 #endif
261 return Handle<T>(T::Cast(*that)); 261 return Handle<T>(T::Cast(*that));
262 } 262 }
263 263
264 template <class S> inline Handle<S> As() {
265 return Handle<S>::Cast(*this);
266 }
267
264 private: 268 private:
265 T* val_; 269 T* val_;
266 }; 270 };
267 271
268 272
269 /** 273 /**
270 * A light-weight stack-allocated object handle. All operations 274 * A light-weight stack-allocated object handle. All operations
271 * that return objects from within v8 return them in local handles. They 275 * that return objects from within v8 return them in local handles. They
272 * are created within HandleScopes, and all local handles allocated within a 276 * are created within HandleScopes, and all local handles allocated within a
273 * handle scope are destroyed when the handle scope is destroyed. Hence it 277 * handle scope are destroyed when the handle scope is destroyed. Hence it
(...skipping 14 matching lines...) Expand all
288 template <class S> inline Local(S* that) : Handle<T>(that) { } 292 template <class S> inline Local(S* that) : Handle<T>(that) { }
289 template <class S> static inline Local<T> Cast(Local<S> that) { 293 template <class S> static inline Local<T> Cast(Local<S> that) {
290 #ifdef V8_ENABLE_CHECKS 294 #ifdef V8_ENABLE_CHECKS
291 // If we're going to perform the type check then we have to check 295 // If we're going to perform the type check then we have to check
292 // that the handle isn't empty before doing the checked cast. 296 // that the handle isn't empty before doing the checked cast.
293 if (that.IsEmpty()) return Local<T>(); 297 if (that.IsEmpty()) return Local<T>();
294 #endif 298 #endif
295 return Local<T>(T::Cast(*that)); 299 return Local<T>(T::Cast(*that));
296 } 300 }
297 301
302 template <class S> inline Local<S> As() {
303 return Local<S>::Cast(*this);
304 }
305
298 /** Create a local handle for the content of another handle. 306 /** Create a local handle for the content of another handle.
299 * The referee is kept alive by the local handle even when 307 * The referee is kept alive by the local handle even when
300 * the original handle is destroyed/disposed. 308 * the original handle is destroyed/disposed.
301 */ 309 */
302 inline static Local<T> New(Handle<T> that); 310 inline static Local<T> New(Handle<T> that);
303 }; 311 };
304 312
305 313
306 /** 314 /**
307 * An object reference that is independent of any handle scope. Where 315 * An object reference that is independent of any handle scope. Where
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 369
362 template <class S> static inline Persistent<T> Cast(Persistent<S> that) { 370 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
363 #ifdef V8_ENABLE_CHECKS 371 #ifdef V8_ENABLE_CHECKS
364 // If we're going to perform the type check then we have to check 372 // If we're going to perform the type check then we have to check
365 // that the handle isn't empty before doing the checked cast. 373 // that the handle isn't empty before doing the checked cast.
366 if (that.IsEmpty()) return Persistent<T>(); 374 if (that.IsEmpty()) return Persistent<T>();
367 #endif 375 #endif
368 return Persistent<T>(T::Cast(*that)); 376 return Persistent<T>(T::Cast(*that));
369 } 377 }
370 378
379 template <class S> inline Persistent<S> As() {
380 return Persistent<S>::Cast(*this);
381 }
382
371 /** 383 /**
372 * Creates a new persistent handle for an existing local or 384 * Creates a new persistent handle for an existing local or
373 * persistent handle. 385 * persistent handle.
374 */ 386 */
375 inline static Persistent<T> New(Handle<T> that); 387 inline static Persistent<T> New(Handle<T> that);
376 388
377 /** 389 /**
378 * Releases the storage cell referenced by this persistent handle. 390 * Releases the storage cell referenced by this persistent handle.
379 * Does not remove the reference to the cell from any handles. 391 * Does not remove the reference to the cell from any handles.
380 * This handle's reference, and any any other references to the storage 392 * This handle's reference, and any any other references to the storage
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 1183
1172 /** 1184 /**
1173 * A JavaScript object (ECMA-262, 4.3.3) 1185 * A JavaScript object (ECMA-262, 4.3.3)
1174 */ 1186 */
1175 class V8EXPORT Object : public Value { 1187 class V8EXPORT Object : public Value {
1176 public: 1188 public:
1177 bool Set(Handle<Value> key, 1189 bool Set(Handle<Value> key,
1178 Handle<Value> value, 1190 Handle<Value> value,
1179 PropertyAttribute attribs = None); 1191 PropertyAttribute attribs = None);
1180 1192
1193 bool Set(uint32_t index,
1194 Handle<Value> value);
1195
1181 // Sets a local property on this object bypassing interceptors and 1196 // Sets a local property on this object bypassing interceptors and
1182 // overriding accessors or read-only properties. 1197 // overriding accessors or read-only properties.
1183 // 1198 //
1184 // Note that if the object has an interceptor the property will be set 1199 // Note that if the object has an interceptor the property will be set
1185 // locally, but since the interceptor takes precedence the local property 1200 // locally, but since the interceptor takes precedence the local property
1186 // will only be returned if the interceptor doesn't return a value. 1201 // will only be returned if the interceptor doesn't return a value.
1187 // 1202 //
1188 // Note also that this only works for named properties. 1203 // Note also that this only works for named properties.
1189 bool ForceSet(Handle<Value> key, 1204 bool ForceSet(Handle<Value> key,
1190 Handle<Value> value, 1205 Handle<Value> value,
1191 PropertyAttribute attribs = None); 1206 PropertyAttribute attribs = None);
1192 1207
1193 Local<Value> Get(Handle<Value> key); 1208 Local<Value> Get(Handle<Value> key);
1194 1209
1210 Local<Value> Get(uint32_t index);
1211
1195 // TODO(1245389): Replace the type-specific versions of these 1212 // TODO(1245389): Replace the type-specific versions of these
1196 // functions with generic ones that accept a Handle<Value> key. 1213 // functions with generic ones that accept a Handle<Value> key.
1197 bool Has(Handle<String> key); 1214 bool Has(Handle<String> key);
1198 1215
1199 bool Delete(Handle<String> key); 1216 bool Delete(Handle<String> key);
1200 1217
1201 // Delete a property on this object bypassing interceptors and 1218 // Delete a property on this object bypassing interceptors and
1202 // ignoring dont-delete attributes. 1219 // ignoring dont-delete attributes.
1203 bool ForceDelete(Handle<Value> key); 1220 bool ForceDelete(Handle<Value> key);
1204 1221
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 3299
3283 } // namespace v8 3300 } // namespace v8
3284 3301
3285 3302
3286 #undef V8EXPORT 3303 #undef V8EXPORT
3287 #undef V8EXPORT_INLINE 3304 #undef V8EXPORT_INLINE
3288 #undef TYPE_CHECK 3305 #undef TYPE_CHECK
3289 3306
3290 3307
3291 #endif // V8_H_ 3308 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698