51 int n = impl->
blocks()->length();
58 Object** HandleScope::Extend() {
63 Object** result = current->next;
65 ASSERT(result == current->limit);
68 if (current->level == 0) {
70 "Cannot create a handle without a HandleScope");
76 if (!impl->blocks()->is_empty()) {
78 if (current->limit != limit) {
79 current->limit = limit;
86 if (result == current->limit) {
88 result = impl->GetSpareOrNewBlock();
91 impl->blocks()->Add(result);
100 ASSERT(isolate == Isolate::Current());
107 void HandleScope::ZapRange(
Object** start,
Object** end) {
109 for (
Object** p = start; p != end; p++) {
116 return reinterpret_cast<Address>(
117 &Isolate::Current()->handle_scope_data()->level);
122 return reinterpret_cast<Address>(
123 &Isolate::Current()->handle_scope_data()->next);
128 return reinterpret_cast<Address>(
129 &Isolate::Current()->handle_scope_data()->limit);
136 content->AddKeysFromJSArray(*array),
FixedArray);
151 constructor->GetIsolate(),
152 constructor->GetHeap()->ReinitializeJSGlobalProxy(*constructor, *global),
163 if (func->shared()->live_objects_may_exist())
return;
165 func->shared()->set_expected_nof_properties(nof);
166 if (func->has_initial_map()) {
168 func->GetIsolate()->factory()->CopyMap(
170 new_initial_map->set_unused_property_fields(nof);
171 func->set_initial_map(*new_initial_map);
178 func->SetPrototype(*value));
182 static int ExpectedNofPropertiesFromEstimate(
int estimate) {
185 if (estimate == 0) estimate = 2;
193 if (FLAG_clever_optimizations) {
204 if (shared->live_objects_may_exist())
return;
206 shared->set_expected_nof_properties(
207 ExpectedNofPropertiesFromEstimate(estimate));
223 ASSERT(function->should_have_prototype());
237 Isolate* isolate = Isolate::Current();
241 isolate,
object, key, value, attributes, strict_mode),
250 Isolate* isolate =
object->GetIsolate();
254 isolate,
object, key, value, attributes),
261 Isolate* isolate =
object->GetIsolate();
274 object->SetPropertyWithInterceptor(*key,
284 Isolate* isolate = obj->GetIsolate();
292 Isolate* isolate = Isolate::Current();
302 Isolate* isolate = receiver->GetIsolate();
304 holder->GetPropertyWithInterceptor(*receiver,
312 const bool skip_hidden_prototypes =
false;
314 obj->SetPrototype(*value, skip_hidden_prototypes),
Object);
319 Isolate* isolate = Isolate::Current();
331 str->SubString(start, end, pretenure),
String);
336 Isolate* isolate = obj->GetIsolate();
356 Foreign* foreign =
Script::cast(wrapper->value())->wrapper();
357 ASSERT(foreign->foreign_address() ==
358 reinterpret_cast<Address>(cache.location()));
359 foreign->set_foreign_address(0);
360 Isolate* isolate = Isolate::Current();
361 isolate->global_handles()->Destroy(cache.location());
362 isolate->counters()->script_wrappers()->Decrement();
367 if (script->wrapper()->foreign_address() !=
NULL) {
370 reinterpret_cast<JSValue**
>(script->wrapper()->foreign_address()));
372 Isolate* isolate = Isolate::Current();
374 isolate->
counters()->script_wrappers()->Increment();
378 result->set_value(*script);
386 script->wrapper()->set_foreign_address(
387 reinterpret_cast<Address>(handle.
location()));
395 if (!script->line_ends()->IsUndefined())
return;
399 if (!script->source()->IsString()) {
400 ASSERT(script->source()->IsUndefined());
402 script->set_line_ends(*empty);
403 ASSERT(script->line_ends()->IsFixedArray());
411 if (*array != isolate->
heap()->empty_fixed_array()) {
412 array->set_map(isolate->
heap()->fixed_cow_array_map());
415 script->set_line_ends(*array);
416 ASSERT(script->line_ends()->IsFixedArray());
420 template <
typename SourceChar>
421 static void CalculateLineEnds(
Isolate* isolate,
422 List<int>* line_ends,
423 Vector<const SourceChar> src,
424 bool with_last_line) {
425 const int src_len = src.length();
426 StringSearch<char, SourceChar> search(isolate,
CStrVector(
"\n"));
430 while (position != -1 && position < src_len) {
431 position = search.Search(src, position);
432 if (position != -1) {
433 line_ends->Add(position);
435 }
else if (with_last_line) {
437 line_ends->Add(src_len);
445 bool with_last_line) {
449 int line_count_estimate = src->length() >> 4;
450 List<int> line_ends(line_count_estimate);
451 Isolate* isolate = src->GetIsolate();
458 CalculateLineEnds(isolate,
463 CalculateLineEnds(isolate,
469 int line_count = line_ends.length();
471 for (
int i = 0; i < line_count; i++) {
483 const int line_ends_len = line_ends_array->
length();
485 if (!line_ends_len)
return -1;
487 if ((
Smi::cast(line_ends_array->
get(0)))->value() >= code_pos) {
488 return script->line_offset()->value();
492 int right = line_ends_len;
493 while (
int half = (right - left) / 2) {
494 if ((
Smi::cast(line_ends_array->
get(left + half)))->value() > code_pos) {
500 return right + script->line_offset()->value();
506 if (line_number == -1)
return -1;
510 line_number = line_number - script->line_offset()->value();
511 if (line_number == 0)
return code_pos + script->column_offset()->value();
512 int prev_line_end_pos =
513 Smi::cast(line_ends_array->
get(line_number - 1))->value();
514 return code_pos - (prev_line_end_pos + 1);
519 if (!script->line_ends()->IsUndefined()) {
523 if (!script->source()->IsString()) {
528 int len = source->
length();
529 for (
int pos = 0; pos < len; pos++) {
530 if (pos == code_pos) {
533 if (source->Get(pos) ==
'\n') {
542 v->VisitPointers(values_, values_ +
ARRAY_SIZE(values_));
549 Isolate* isolate = receiver->GetIsolate();
551 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
554 if (!interceptor->enumerator()->IsUndefined()) {
556 v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator());
557 LOG(isolate, ApiObjectAccess(
"interceptor-named-enum", *
object));
560 VMState state(isolate, EXTERNAL);
561 result = enum_fun(info);
564 #if ENABLE_EXTRA_CHECKS
565 CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
574 Isolate* isolate = receiver->GetIsolate();
576 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
579 if (!interceptor->enumerator()->IsUndefined()) {
581 v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator());
582 LOG(isolate, ApiObjectAccess(
"interceptor-indexed-enum", *
object));
585 VMState state(isolate, EXTERNAL);
586 result = enum_fun(info);
587 #if ENABLE_EXTRA_CHECKS
588 CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
597 int len = array->
length();
598 for (
int i = 0; i < len; i++) {
609 USE(ContainsOnlyValidKeys);
610 Isolate* isolate =
object->GetIsolate();
621 *p != isolate->
heap()->null_value();
623 if (p->IsJSProxy()) {
627 isolate->proxy_enumerate(), object,
ARRAY_SIZE(args), args, threw);
628 if (*threw)
return content;
636 if (current->IsAccessCheckNeeded() &&
638 isolate->
heap()->undefined_value(),
647 current->GetEnumElementKeys(*element_keys);
649 ASSERT(ContainsOnlyValidKeys(content));
652 if (current->HasIndexedInterceptor()) {
657 ASSERT(ContainsOnlyValidKeys(content));
670 bool cache_enum_keys =
671 ((current->map()->constructor() != *arguments_function) &&
672 !current->IsJSValue() &&
673 !current->IsAccessCheckNeeded() &&
674 !current->HasNamedInterceptor() &&
675 !current->HasIndexedInterceptor());
679 ASSERT(ContainsOnlyValidKeys(content));
682 if (current->HasNamedInterceptor()) {
687 ASSERT(ContainsOnlyValidKeys(content));
700 Isolate* isolate =
object->GetIsolate();
701 isolate->
counters()->for_in()->Increment();
709 ASSERT(array->length() >= length);
710 if (array->length() == length)
return array;
713 array->GetIsolate()->factory()->NewFixedArray(length);
714 for (
int i = 0; i < length; ++i) new_array->set(i, array->get(i));
721 Isolate* isolate =
object->GetIsolate();
722 if (object->HasFastProperties()) {
723 if (object->map()->instance_descriptors()->HasEnumCache()) {
724 int own_property_count =
object->map()->EnumLength();
731 own_property_count =
object->map()->NumberOfDescribedProperties(
734 if (cache_result)
object->map()->SetEnumLength(own_property_count);
744 if (own_property_count <= keys->length()) {
745 isolate->
counters()->enum_cache_hits()->Increment();
752 if (map->instance_descriptors()->IsEmpty()) {
753 isolate->
counters()->enum_cache_hits()->Increment();
754 if (cache_result) map->SetEnumLength(0);
755 return isolate->
factory()->empty_fixed_array();
758 isolate->
counters()->enum_cache_misses()->Increment();
767 int real_size = map->NumberOfOwnDescriptors();
771 for (
int i = 0; i < descs->number_of_descriptors(); i++) {
772 PropertyDetails details = descs->GetDetails(i);
773 if (!details.IsDontEnum()) {
774 if (i < real_size) ++enum_size;
775 storage->set(index, descs->GetKey(i));
777 if (details.type() !=
FIELD) {
780 int field_index = Descriptor::IndexFromValue(descs->GetValue(i));
781 if (field_index >= map->inobject_properties()) {
782 field_index = -(field_index - map->inobject_properties() + 1);
790 ASSERT(index == storage->length());
801 object->map()->SetEnumLength(enum_size);
808 int length = dictionary->NumberOfElements();
825 int next_enumeration = dictionary->NextEnumerationIndex();
826 if (!object->IsGlobalObject() && next_enumeration > (length * 3) / 2) {
828 next_enumeration = dictionary->NextEnumerationIndex();
835 ASSERT(storage->length() ==
object->NumberOfLocalProperties(
DONT_ENUM));
861 table->Put(*key, *value),
891 bool followed_by_surrogate,
894 bool* starts_with_surrogate) {
895 if (from == to)
return 0;
900 *starts_with_surrogate =
false;
901 return total + to - from;
903 switch (StringShape(input).representation_tag()) {
908 int first_length = first->
length();
909 if (first_length - from > to - first_length) {
910 if (first_length < to) {
913 bool right_starts_with_surrogate =
false;
917 followed_by_surrogate,
920 &right_starts_with_surrogate);
921 if (*failure)
return 0;
922 followed_by_surrogate = right_starts_with_surrogate;
930 if (first_length > from) {
933 total += first_length - from;
934 *starts_with_surrogate =
false;
935 starts_with_surrogate = &dummy;
940 followed_by_surrogate =
false;
941 total += to - first_length;
944 }
else if (max_recursion > 0) {
945 bool right_starts_with_surrogate =
false;
950 followed_by_surrogate,
953 &right_starts_with_surrogate);
954 if (*failure)
return 0;
957 followed_by_surrogate = right_starts_with_surrogate;
976 for (
int i = from; i < to; i++) {
983 followed_by_surrogate) {
987 *starts_with_surrogate =
true;
994 int offset = str->
offset();
1014 const int kRecursionBudget = 100;
1018 *str, 0, str->length(),
false, kRecursionBudget, &failure, &dummy);
1026 : impl_(isolate->handle_scope_implementer()) {
1028 impl_->BeginDeferredScope();
1034 impl_->
blocks()->Add(new_next);
1037 prev_level_ = data->level;
1040 prev_limit_ = data->limit;
1041 prev_next_ = data->next;
1042 data->next = new_next;
1043 data->limit = new_limit;
1049 ASSERT(handles_detached_);
1058 data->next = prev_next_;
1059 data->limit = prev_limit_;
1061 handles_detached_ =
true;
int Utf8Length(Handle< String > str)
void SetEnumCache(FixedArray *bridge_storage, FixedArray *new_cache, Object *new_index_cache)
Handle< Array >(* NamedPropertyEnumerator)(const AccessorInfo &info)
void FlattenString(Handle< String > string)
static int NumberOfHandles()
internal::Object ** GetSpareOrNewBlock()
Handle< JSObject > NewJSObject(Handle< JSFunction > constructor, PretenureFlag pretenure=NOT_TENURED)
static Address current_level_address()
static void DoGenerateNewEnumerationIndices(Handle< StringDictionary > dictionary)
static String * cast(Object *obj)
Handle< FixedArray > AddKeysFromJSArray(Handle< FixedArray > content, Handle< JSArray > array)
HandleScopeImplementer * handle_scope_implementer()
Handle< Object > SetPropertyWithInterceptor(Handle< JSObject > object, Handle< String > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
static Smi * FromInt(int value)
v8::Handle< v8::Array > GetKeysForIndexedInterceptor(Handle< JSReceiver > receiver, Handle< JSObject > object)
#define LOG(isolate, Call)
void ReportFailedAccessCheck(JSObject *receiver, v8::AccessType type)
static MUST_USE_RESULT MaybeObject * ForceDeleteObjectProperty(Isolate *isolate, Handle< JSReceiver > object, Handle< Object > key)
static Handle< T > cast(Handle< S > that)
bool MayNamedAccess(JSObject *receiver, Object *key, v8::AccessType type)
bool IsAsciiRepresentation()
Vector< const char > ToAsciiVector()
static const int kEnumCacheBridgeLength
v8::HandleScope::Data HandleScopeData
static MUST_USE_RESULT MaybeObject * SetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr, StrictModeFlag strict_mode)
Handle< Object > SetAccessor(Handle< JSObject > obj, Handle< AccessorInfo > info)
void DeleteExtensions(internal::Object **prev_limit)
void SetPrototypeProperty(Handle< JSFunction > func, Handle< JSObject > value)
static Address current_next_address()
Handle< FixedArray > UnionOfKeys(Handle< FixedArray > first, Handle< FixedArray > second)
void InitScriptLineEnds(Handle< Script > script)
#define ASSERT(condition)
Handle< JSArray > GetKeysFor(Handle< JSReceiver > object, bool *threw)
static Script * cast(Object *obj)
#define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL)
Handle< Object > GetPropertyWithInterceptor(Handle< JSObject > receiver, Handle< JSObject > holder, Handle< String > name, PropertyAttributes *attributes)
int GetScriptColumnNumber(Handle< Script > script, int code_pos)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
MUST_USE_RESULT MaybeObject * CopyJSObject(JSObject *source)
Handle< String > LookupAsciiSymbol(Vector< const char > str)
static Smi * cast(Object *object)
Handle< String > FlattenGetString(Handle< String > string)
Handle< Object > ForceDeleteProperty(Handle< JSObject > object, Handle< Object > key)
static const int kInvalidEnumCache
static Address current_limit_address()
Handle< String > SubString(Handle< String > str, int start, int end, PretenureFlag pretenure)
DeferredHandleScope(Isolate *isolate)
static uchar Length(uchar chr, int previous)
Handle< FixedArray > ReduceFixedArrayTo(Handle< FixedArray > array, int length)
DeferredHandles * Detach()
Handle< Object > LookupSingleCharacterStringFromCode(uint32_t index)
void SetExpectedNofProperties(Handle< JSFunction > func, int nof)
static SlicedString * cast(Object *obj)
int Utf8LengthHelper(String *input, int from, int to, bool followed_by_surrogate, int max_recursion, bool *failure, bool *starts_with_surrogate)
Context * native_context()
Handle< Object > Create(Object *value)
#define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE)
Handle< ObjectHashSet > ObjectHashSetAdd(Handle< ObjectHashSet > table, Handle< Object > key)
Handle< Object > SetProperty(Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
GlobalHandles * global_handles()
Handle< JSValue > GetScriptWrapper(Handle< Script > script)
Vector< const uc16 > ToUC16Vector()
Handle< FixedArray > NewFixedArray(int size, PretenureFlag pretenure=NOT_TENURED)
v8::ImplementationUtilities::HandleScopeData * handle_scope_data()
int GetScriptLineNumberSafe(Handle< Script > script, int code_pos)
Handle< FixedArray > GetKeysInFixedArrayFor(Handle< JSReceiver > object, KeyCollectionType type, bool *threw)
static Handle< Object > Call(Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *pending_exception, bool convert_receiver=false)
Vector< const char > CStrVector(const char *data)
Handle< ObjectHashTable > PutIntoObjectHashTable(Handle< ObjectHashTable > table, Handle< Object > key, Handle< Object > value)
Handle< JSArray > NewJSArrayWithElements(Handle< FixedArrayBase > elements, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure=NOT_TENURED)
List< internal::Object ** > * blocks()
FlatContent GetFlatContent()
int GetScriptLineNumber(Handle< Script > script, int code_pos)
static MUST_USE_RESULT MaybeObject * FunctionSetPrototype(JSObject *object, Object *value, void *)
v8::Handle< v8::Array > GetKeysForNamedInterceptor(Handle< JSReceiver > receiver, Handle< JSObject > object)
V8EXPORT bool IsNumber() const
static Object * cast(Object *value)
static JSValue * cast(Object *obj)
static const unsigned kBytesSavedByCombiningSurrogates
Handle< JSGlobalProxy > ReinitializeJSGlobalProxy(Handle< JSFunction > constructor, Handle< JSGlobalProxy > global)
const int kHandleBlockSize
static MUST_USE_RESULT MaybeObject * GetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property keys(0 means random)" "(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption
MUST_USE_RESULT MaybeObject * LookupSingleCharacterStringFromCode(uint16_t code)
static MUST_USE_RESULT MaybeObject * ForceSetObjectProperty(Isolate *isolate, Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr)
static JSProxy * cast(Object *obj)
void IterateInstance(ObjectVisitor *v)
Isolate * isolate() const
static FixedArray * cast(Object *obj)
static bool ReportApiFailure(const char *location, const char *message)
FixedArray * GetEnumCache()
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static bool IsLeadSurrogate(int code)
Handle< Object > ForceSetProperty(Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes)
Handle< ObjectHashSet > ObjectHashSetRemove(Handle< ObjectHashSet > table, Handle< Object > key)
void SetExpectedNofPropertiesFromEstimate(Handle< SharedFunctionInfo > shared, int estimate)
static bool IsTrailSurrogate(int code)
void MakeWeak(Object **location, void *parameter, WeakReferenceCallback callback)
Handle< Object > SetPrototype(Handle< JSFunction > function, Handle< Object > prototype)
Handle< FixedArray > GetEnumPropertyKeys(Handle< JSObject > object, bool cache_result)
static ConsString * cast(Object *obj)
Handle< Array >(* IndexedPropertyEnumerator)(const AccessorInfo &info)
static JSObject * cast(Object *obj)
const Address kHandleZapValue
static const int kNoPreviousCharacter
static void DeleteExtensions(Isolate *isolate)
Handle< JSObject > Copy(Handle< JSObject > obj)
static JSFunction * cast(Object *obj)