13fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Copyright 2011 the V8 project authors. All rights reserved. 2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without 3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met: 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions of source code must retain the above copyright 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// notice, this list of conditions and the following disclaimer. 8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions in binary form must reproduce the above 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// copyright notice, this list of conditions and the following 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// disclaimer in the documentation and/or other materials provided 11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// with the distribution. 12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Neither the name of Google Inc. nor the names of its 13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// contributors may be used to endorse or promote products derived 14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// from this software without specific prior written permission. 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_HANDLES_H_ 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_HANDLES_H_ 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 31257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch#include "allocation.h" 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "apiutils.h" 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 { 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ---------------------------------------------------------------------------- 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A Handle provides a reference to an object that survives relocation by 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the garbage collector. 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Handles are only valid within a HandleScope. 41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// When a handle is created for an object a cell is allocated in the heap. 42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 43e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdochtemplate<typename T> 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Handle { 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block INLINE(explicit Handle(T** location)) { location_ = location; } 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block INLINE(explicit Handle(T* obj)); 4844f0eee88ff00398ff7f715fab053374d808c90dSteve Block INLINE(Handle(T* obj, Isolate* isolate)); 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block INLINE(Handle()) : location_(NULL) {} 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Constructor for handling automatic up casting. 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. 54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> Handle(Handle<S> handle) { 55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG 56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block T* a = NULL; 57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block S* b = NULL; 58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block a = b; // Fake assignment to enforce type checks. 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block USE(a); 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block location_ = reinterpret_cast<T**>(handle.location()); 62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block INLINE(T* operator ->() const) { return operator*(); } 65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Check if this handle refers to the exact same object as the other handle. 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool is_identical_to(const Handle<T> other) const { 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return operator*() == *other; 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Provides the C++ dereference operator. 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block INLINE(T* operator*() const); 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Returns the address to where the raw pointer is stored. 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block T** location() const { 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ASSERT(location_ == NULL || 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block reinterpret_cast<Address>(*location_) != kZapValue); 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return location_; 79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> static Handle<T> cast(Handle<S> that) { 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block T::cast(*that); 83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Handle<T>(reinterpret_cast<T**>(that.location())); 84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Handle<T> null() { return Handle<T>(); } 8744f0eee88ff00398ff7f715fab053374d808c90dSteve Block bool is_null() const { return location_ == NULL; } 88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Closes the given scope, but lets this handle escape. See 90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // implementation in api.h. 91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Handle<T> EscapeFrom(v8::HandleScope* scope); 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block T** location_; 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A stack-allocated class that governs a number of local handles. 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// After a handle scope has been created, all local handles will be 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// allocated within that handle scope until either the handle scope is 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// deleted or another handle scope is created. If there is already a 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// handle scope and a new one is created, all allocations will take 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// place in the new handle scope until it is deleted. After that, 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// new handles will again be allocated in the original handle scope. 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// After the handle scope of a local handle has been deleted the 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// garbage collector will no longer track the object stored in the 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// handle and may deallocate it. The behavior of accessing a handle 109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// for which the handle scope has been deleted is undefined. 110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass HandleScope { 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 11244f0eee88ff00398ff7f715fab053374d808c90dSteve Block inline HandleScope(); 11344f0eee88ff00398ff7f715fab053374d808c90dSteve Block explicit inline HandleScope(Isolate* isolate); 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 11544f0eee88ff00398ff7f715fab053374d808c90dSteve Block inline ~HandleScope(); 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Counts the number of allocated handles. 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int NumberOfHandles(); 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Creates a new handle with the given value. 121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <typename T> 12244f0eee88ff00398ff7f715fab053374d808c90dSteve Block static inline T** CreateHandle(T* value, Isolate* isolate); 123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 124d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block // Deallocates any extensions used by the current scope. 12544f0eee88ff00398ff7f715fab053374d808c90dSteve Block static void DeleteExtensions(Isolate* isolate); 126d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 127d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block static Address current_next_address(); 128d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block static Address current_limit_address(); 1295913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck static Address current_level_address(); 130d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 131e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch // Closes the HandleScope (invalidating all handles 132e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch // created in the scope of the HandleScope) and returns 133e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch // a Handle backed by the parent scope holding the 134e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch // value of the argument handle. 135e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch template <typename T> 13644f0eee88ff00398ff7f715fab053374d808c90dSteve Block Handle<T> CloseAndEscape(Handle<T> handle_value); 13744f0eee88ff00398ff7f715fab053374d808c90dSteve Block 13844f0eee88ff00398ff7f715fab053374d808c90dSteve Block Isolate* isolate() { return isolate_; } 139e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch 140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Prevent heap allocation or illegal handle scopes. 142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block HandleScope(const HandleScope&); 143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const HandleScope&); 144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* operator new(size_t size); 145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator delete(void* size_t); 146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14744f0eee88ff00398ff7f715fab053374d808c90dSteve Block inline void CloseScope(); 148e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch 14944f0eee88ff00398ff7f715fab053374d808c90dSteve Block Isolate* isolate_; 150e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch Object** prev_next_; 151e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch Object** prev_limit_; 152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Extend the handle scope making room for more handles. 154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static internal::Object** Extend(); 155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Zaps the handles in the half-open interval [start, end). 157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ZapRange(internal::Object** start, internal::Object** end); 158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class v8::HandleScope; 160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class v8::ImplementationUtilities; 161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ---------------------------------------------------------------------------- 165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Handle operations. 166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// They might invoke garbage collection. The result is an handle to 167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// an object of expected type, or the handle is an error if running out 168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// of space or encountering an internal error. 169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1708defd9ff6930b4e24729971a61cf7469daf119beSteve Block// Flattens a string. 171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid FlattenString(Handle<String> str); 172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1738defd9ff6930b4e24729971a61cf7469daf119beSteve Block// Flattens a string and returns the underlying external or sequential 1748defd9ff6930b4e24729971a61cf7469daf119beSteve Block// string. 1758defd9ff6930b4e24729971a61cf7469daf119beSteve BlockHandle<String> FlattenGetString(Handle<String> str); 1765d4cdbf7a67d3662fa0bee4efdb7edd8daec9b0bBen Murdoch 1773ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochint Utf8Length(Handle<String> str); 1788defd9ff6930b4e24729971a61cf7469daf119beSteve Block 179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> SetProperty(Handle<Object> object, 180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> key, 181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value, 182e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch PropertyAttributes attributes, 183e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch StrictModeFlag strict_mode); 184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> ForceSetProperty(Handle<JSObject> object, 186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> key, 187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value, 188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PropertyAttributes attributes); 189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> ForceDeleteProperty(Handle<JSObject> object, 191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> key); 192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1933fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochHandle<Object> GetProperty(Handle<JSReceiver> obj, 194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* name); 195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> GetProperty(Handle<Object> obj, 197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> key); 198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver, 200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSObject> holder, 201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name, 202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PropertyAttributes* attributes); 203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 204402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuHandle<Object> SetPrototype(Handle<JSObject> obj, Handle<Object> value); 205402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> LookupSingleCharacterStringFromCode(uint32_t index); 207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<JSObject> Copy(Handle<JSObject> obj); 209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 210f7060e27768c550ace7ec48ad8c093466db52dfaLeon ClarkeHandle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info); 211f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<FixedArray> AddKeysFromJSArray(Handle<FixedArray>, 213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSArray> array); 214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Get the JS object corresponding to the given script; create it 216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// if none exists. 217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<JSValue> GetScriptWrapper(Handle<Script> script); 218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Script line number computations. 220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid InitScriptLineEnds(Handle<Script> script); 2216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// For string calculates an array of line end positions. If the string 2226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// does not end with a new line character, this character may optionally be 2236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// imagined. 2246ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockHandle<FixedArray> CalculateLineEnds(Handle<String> string, 2256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block bool with_imaginary_last_new_line); 226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint GetScriptLineNumber(Handle<Script> script, int code_position); 2276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// The safe version does not make heap allocations but may work much slower. 2286ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockint GetScriptLineNumberSafe(Handle<Script> script, int code_position); 2293ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochint GetScriptColumnNumber(Handle<Script> script, int code_position); 230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Computes the enumerable keys from interceptors. Used for debug mirrors and 232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// by GetKeysInFixedArrayFor below. 2333ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochv8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver, 234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSObject> object); 2353ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochv8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver, 236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSObject> object); 237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum KeyCollectionType { LOCAL_ONLY, INCLUDE_PROTOS }; 239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Computes the enumerable keys for a JSObject. Used for implementing 241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "for (n in object) { }". 2423ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochHandle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object, 2433ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch KeyCollectionType type, 2443ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch bool* threw); 2453ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochHandle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw); 246d0582a6c46733687d045e4188a1bcd0123c758a1Steve BlockHandle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, 247d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block bool cache_result); 248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Computes the union of keys and return the result. 250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Used for implementing "for (n in object) { }" 251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<FixedArray> UnionOfKeys(Handle<FixedArray> first, 252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<FixedArray> second); 253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2546ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockHandle<String> SubString(Handle<String> str, 2556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block int start, 2566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block int end, 2576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block PretenureFlag pretenure = NOT_TENURED); 258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Sets the expected number of properties for the function's instances. 260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid SetExpectedNofProperties(Handle<JSFunction> func, int nof); 261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Sets the prototype property for a function instance. 263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid SetPrototypeProperty(Handle<JSFunction> func, Handle<JSObject> value); 264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Sets the expected number of properties based on estimate from compiler. 266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared, 267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int estimate); 268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<JSGlobalProxy> ReinitializeJSGlobalProxy( 271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSFunction> constructor, 272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSGlobalProxy> global); 273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Object> SetPrototype(Handle<JSFunction> function, 275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> prototype); 276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2773ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochHandle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table, 2783ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch Handle<Object> key); 2793ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 2803ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochHandle<ObjectHashSet> ObjectHashSetRemove(Handle<ObjectHashSet> table, 2813ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch Handle<Object> key); 2824515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 283592a9fc1d8ea420377a2e7efd0600e20b058be2bBen MurdochHandle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table, 2843ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch Handle<Object> key, 285592a9fc1d8ea420377a2e7efd0600e20b058be2bBen Murdoch Handle<Object> value); 286b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch 287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass NoHandleAllocation BASE_EMBEDDED { 288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef DEBUG 290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NoHandleAllocation() {} 291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~NoHandleAllocation() {} 292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else 293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline NoHandleAllocation(); 294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline ~NoHandleAllocation(); 295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2965913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck int level_; 297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} } // namespace v8::internal 301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // V8_HANDLES_H_ 303