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

Side by Side Diff: src/objects.cc

Issue 237673014: Move functions from handles.cc to where they belong. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "execution.h" 42 #include "execution.h"
43 #include "full-codegen.h" 43 #include "full-codegen.h"
44 #include "hydrogen.h" 44 #include "hydrogen.h"
45 #include "isolate-inl.h" 45 #include "isolate-inl.h"
46 #include "log.h" 46 #include "log.h"
47 #include "objects-inl.h" 47 #include "objects-inl.h"
48 #include "objects-visiting-inl.h" 48 #include "objects-visiting-inl.h"
49 #include "macro-assembler.h" 49 #include "macro-assembler.h"
50 #include "mark-compact.h" 50 #include "mark-compact.h"
51 #include "safepoint-table.h" 51 #include "safepoint-table.h"
52 #include "string-search.h"
52 #include "string-stream.h" 53 #include "string-stream.h"
53 #include "utils.h" 54 #include "utils.h"
54 55
55 #ifdef ENABLE_DISASSEMBLER 56 #ifdef ENABLE_DISASSEMBLER
56 #include "disasm.h" 57 #include "disasm.h"
57 #include "disassembler.h" 58 #include "disassembler.h"
58 #endif 59 #endif
59 60
60 namespace v8 { 61 namespace v8 {
61 namespace internal { 62 namespace internal {
(...skipping 6181 matching lines...) Expand 10 before | Expand all | Expand 10 after
6243 for (Object* current = this; 6244 for (Object* current = this;
6244 current != heap->null_value() && current->IsJSObject(); 6245 current != heap->null_value() && current->IsJSObject();
6245 current = JSObject::cast(current)->GetPrototype()) { 6246 current = JSObject::cast(current)->GetPrototype()) {
6246 JSObject::cast(current)->LocalLookupRealNamedProperty(name, result); 6247 JSObject::cast(current)->LocalLookupRealNamedProperty(name, result);
6247 if (result->IsPropertyCallbacks()) return; 6248 if (result->IsPropertyCallbacks()) return;
6248 } 6249 }
6249 result->NotFound(); 6250 result->NotFound();
6250 } 6251 }
6251 6252
6252 6253
6254 static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
6255 int len = array->length();
6256 for (int i = 0; i < len; i++) {
6257 Object* e = array->get(i);
6258 if (!(e->IsString() || e->IsNumber())) return false;
6259 }
6260 return true;
6261 }
6262
6263
6264 static Handle<FixedArray> ReduceFixedArrayTo(
6265 Handle<FixedArray> array, int length) {
6266 ASSERT(array->length() >= length);
6267 if (array->length() == length) return array;
6268
6269 Handle<FixedArray> new_array =
6270 array->GetIsolate()->factory()->NewFixedArray(length);
6271 for (int i = 0; i < length; ++i) new_array->set(i, array->get(i));
6272 return new_array;
6273 }
6274
6275
6276 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
6277 bool cache_result) {
6278 Isolate* isolate = object->GetIsolate();
6279 if (object->HasFastProperties()) {
6280 int own_property_count = object->map()->EnumLength();
6281 // If the enum length of the given map is set to kInvalidEnumCache, this
6282 // means that the map itself has never used the present enum cache. The
6283 // first step to using the cache is to set the enum length of the map by
6284 // counting the number of own descriptors that are not DONT_ENUM or
6285 // SYMBOLIC.
6286 if (own_property_count == kInvalidEnumCacheSentinel) {
6287 own_property_count = object->map()->NumberOfDescribedProperties(
6288 OWN_DESCRIPTORS, DONT_SHOW);
6289 } else {
6290 ASSERT(own_property_count == object->map()->NumberOfDescribedProperties(
6291 OWN_DESCRIPTORS, DONT_SHOW));
6292 }
6293
6294 if (object->map()->instance_descriptors()->HasEnumCache()) {
6295 DescriptorArray* desc = object->map()->instance_descriptors();
6296 Handle<FixedArray> keys(desc->GetEnumCache(), isolate);
6297
6298 // In case the number of properties required in the enum are actually
6299 // present, we can reuse the enum cache. Otherwise, this means that the
6300 // enum cache was generated for a previous (smaller) version of the
6301 // Descriptor Array. In that case we regenerate the enum cache.
6302 if (own_property_count <= keys->length()) {
6303 if (cache_result) object->map()->SetEnumLength(own_property_count);
6304 isolate->counters()->enum_cache_hits()->Increment();
6305 return ReduceFixedArrayTo(keys, own_property_count);
6306 }
6307 }
6308
6309 Handle<Map> map(object->map());
6310
6311 if (map->instance_descriptors()->IsEmpty()) {
6312 isolate->counters()->enum_cache_hits()->Increment();
6313 if (cache_result) map->SetEnumLength(0);
6314 return isolate->factory()->empty_fixed_array();
6315 }
6316
6317 isolate->counters()->enum_cache_misses()->Increment();
6318
6319 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(
6320 own_property_count);
6321 Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
6322 own_property_count);
6323
6324 Handle<DescriptorArray> descs =
6325 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate);
6326
6327 int size = map->NumberOfOwnDescriptors();
6328 int index = 0;
6329
6330 for (int i = 0; i < size; i++) {
6331 PropertyDetails details = descs->GetDetails(i);
6332 Object* key = descs->GetKey(i);
6333 if (!(details.IsDontEnum() || key->IsSymbol())) {
6334 storage->set(index, key);
6335 if (!indices.is_null()) {
6336 if (details.type() != FIELD) {
6337 indices = Handle<FixedArray>();
6338 } else {
6339 int field_index = descs->GetFieldIndex(i);
6340 if (field_index >= map->inobject_properties()) {
6341 field_index = -(field_index - map->inobject_properties() + 1);
6342 }
6343 field_index = field_index << 1;
6344 if (details.representation().IsDouble()) {
6345 field_index |= 1;
6346 }
6347 indices->set(index, Smi::FromInt(field_index));
6348 }
6349 }
6350 index++;
6351 }
6352 }
6353 ASSERT(index == storage->length());
6354
6355 Handle<FixedArray> bridge_storage =
6356 isolate->factory()->NewFixedArray(
6357 DescriptorArray::kEnumCacheBridgeLength);
6358 DescriptorArray* desc = object->map()->instance_descriptors();
6359 desc->SetEnumCache(*bridge_storage,
6360 *storage,
6361 indices.is_null() ? Object::cast(Smi::FromInt(0))
6362 : Object::cast(*indices));
6363 if (cache_result) {
6364 object->map()->SetEnumLength(own_property_count);
6365 }
6366 return storage;
6367 } else {
6368 Handle<NameDictionary> dictionary(object->property_dictionary());
6369 int length = dictionary->NumberOfEnumElements();
6370 if (length == 0) {
6371 return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
6372 }
6373 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
6374 dictionary->CopyEnumKeysTo(*storage);
6375 return storage;
6376 }
6377 }
6378
6379
6380 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
6381 KeyCollectionType type) {
6382 USE(ContainsOnlyValidKeys);
6383 Isolate* isolate = object->GetIsolate();
6384 Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
6385 Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
6386 isolate->context()->native_context()->sloppy_arguments_boilerplate(),
6387 isolate);
6388 Handle<JSFunction> arguments_function = Handle<JSFunction>(
6389 JSFunction::cast(arguments_boilerplate->map()->constructor()),
6390 isolate);
6391
6392 // Only collect keys if access is permitted.
6393 for (Handle<Object> p = object;
6394 *p != isolate->heap()->null_value();
6395 p = Handle<Object>(p->GetPrototype(isolate), isolate)) {
6396 if (p->IsJSProxy()) {
6397 Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
6398 Handle<Object> args[] = { proxy };
6399 Handle<Object> names;
6400 ASSIGN_RETURN_ON_EXCEPTION(
6401 isolate, names,
6402 Execution::Call(isolate,
6403 isolate->proxy_enumerate(),
6404 object,
6405 ARRAY_SIZE(args),
6406 args),
6407 FixedArray);
6408 ASSIGN_RETURN_ON_EXCEPTION(
6409 isolate, content,
6410 FixedArray::AddKeysFromJSArray(
6411 content, Handle<JSArray>::cast(names)),
6412 FixedArray);
6413 break;
6414 }
6415
6416 Handle<JSObject> current(JSObject::cast(*p), isolate);
6417
6418 // Check access rights if required.
6419 if (current->IsAccessCheckNeeded() &&
6420 !isolate->MayNamedAccess(
6421 current, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) {
6422 isolate->ReportFailedAccessCheck(current, v8::ACCESS_KEYS);
6423 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
6424 break;
6425 }
6426
6427 // Compute the element keys.
6428 Handle<FixedArray> element_keys =
6429 isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
6430 current->GetEnumElementKeys(*element_keys);
6431 ASSIGN_RETURN_ON_EXCEPTION(
6432 isolate, content,
6433 FixedArray::UnionOfKeys(content, element_keys),
6434 FixedArray);
6435 ASSERT(ContainsOnlyValidKeys(content));
6436
6437 // Add the element keys from the interceptor.
6438 if (current->HasIndexedInterceptor()) {
6439 Handle<JSArray> result;
6440 if (JSObject::GetKeysForIndexedInterceptor(
6441 current, object).ToHandle(&result)) {
6442 ASSIGN_RETURN_ON_EXCEPTION(
6443 isolate, content,
6444 FixedArray::AddKeysFromJSArray(content, result),
6445 FixedArray);
6446 }
6447 ASSERT(ContainsOnlyValidKeys(content));
6448 }
6449
6450 // We can cache the computed property keys if access checks are
6451 // not needed and no interceptors are involved.
6452 //
6453 // We do not use the cache if the object has elements and
6454 // therefore it does not make sense to cache the property names
6455 // for arguments objects. Arguments objects will always have
6456 // elements.
6457 // Wrapped strings have elements, but don't have an elements
6458 // array or dictionary. So the fast inline test for whether to
6459 // use the cache says yes, so we should not create a cache.
6460 bool cache_enum_keys =
6461 ((current->map()->constructor() != *arguments_function) &&
6462 !current->IsJSValue() &&
6463 !current->IsAccessCheckNeeded() &&
6464 !current->HasNamedInterceptor() &&
6465 !current->HasIndexedInterceptor());
6466 // Compute the property keys and cache them if possible.
6467 ASSIGN_RETURN_ON_EXCEPTION(
6468 isolate, content,
6469 FixedArray::UnionOfKeys(
6470 content, GetEnumPropertyKeys(current, cache_enum_keys)),
6471 FixedArray);
6472 ASSERT(ContainsOnlyValidKeys(content));
6473
6474 // Add the property keys from the interceptor.
6475 if (current->HasNamedInterceptor()) {
6476 Handle<JSArray> result;
6477 if (JSObject::GetKeysForNamedInterceptor(
6478 current, object).ToHandle(&result)) {
6479 ASSIGN_RETURN_ON_EXCEPTION(
6480 isolate, content,
6481 FixedArray::AddKeysFromJSArray(content, result),
6482 FixedArray);
6483 }
6484 ASSERT(ContainsOnlyValidKeys(content));
6485 }
6486
6487 // If we only want local properties we bail out after the first
6488 // iteration.
6489 if (type == LOCAL_ONLY) break;
6490 }
6491 return content;
6492 }
6493
6494
6253 // Try to update an accessor in an elements dictionary. Return true if the 6495 // Try to update an accessor in an elements dictionary. Return true if the
6254 // update succeeded, and false otherwise. 6496 // update succeeded, and false otherwise.
6255 static bool UpdateGetterSetterInDictionary( 6497 static bool UpdateGetterSetterInDictionary(
6256 SeededNumberDictionary* dictionary, 6498 SeededNumberDictionary* dictionary,
6257 uint32_t index, 6499 uint32_t index,
6258 Object* getter, 6500 Object* getter,
6259 Object* setter, 6501 Object* setter,
6260 PropertyAttributes attributes) { 6502 PropertyAttributes attributes) {
6261 int entry = dictionary->FindEntry(index); 6503 int entry = dictionary->FindEntry(index);
6262 if (entry != SeededNumberDictionary::kNotFound) { 6504 if (entry != SeededNumberDictionary::kNotFound) {
(...skipping 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after
8897 SlicedString* slice = SlicedString::cast(source); 9139 SlicedString* slice = SlicedString::cast(source);
8898 unsigned offset = slice->offset(); 9140 unsigned offset = slice->offset();
8899 WriteToFlat(slice->parent(), sink, from + offset, to + offset); 9141 WriteToFlat(slice->parent(), sink, from + offset, to + offset);
8900 return; 9142 return;
8901 } 9143 }
8902 } 9144 }
8903 } 9145 }
8904 } 9146 }
8905 9147
8906 9148
9149
9150 template <typename SourceChar>
9151 static void CalculateLineEndsImpl(Isolate* isolate,
9152 List<int>* line_ends,
9153 Vector<const SourceChar> src,
9154 bool include_ending_line) {
9155 const int src_len = src.length();
9156 StringSearch<uint8_t, SourceChar> search(isolate, STATIC_ASCII_VECTOR("\n"));
9157
9158 // Find and record line ends.
9159 int position = 0;
9160 while (position != -1 && position < src_len) {
9161 position = search.Search(src, position);
9162 if (position != -1) {
9163 line_ends->Add(position);
9164 position++;
9165 } else if (include_ending_line) {
9166 // Even if the last line misses a line end, it is counted.
9167 line_ends->Add(src_len);
9168 return;
9169 }
9170 }
9171 }
9172
9173
9174 Handle<FixedArray> String::CalculateLineEnds(Handle<String> src,
9175 bool include_ending_line) {
9176 src = Flatten(src);
9177 // Rough estimate of line count based on a roughly estimated average
9178 // length of (unpacked) code.
9179 int line_count_estimate = src->length() >> 4;
9180 List<int> line_ends(line_count_estimate);
9181 Isolate* isolate = src->GetIsolate();
9182 { DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
9183 // Dispatch on type of strings.
9184 String::FlatContent content = src->GetFlatContent();
9185 ASSERT(content.IsFlat());
9186 if (content.IsAscii()) {
9187 CalculateLineEndsImpl(isolate,
9188 &line_ends,
9189 content.ToOneByteVector(),
9190 include_ending_line);
9191 } else {
9192 CalculateLineEndsImpl(isolate,
9193 &line_ends,
9194 content.ToUC16Vector(),
9195 include_ending_line);
9196 }
9197 }
9198 int line_count = line_ends.length();
9199 Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
9200 for (int i = 0; i < line_count; i++) {
9201 array->set(i, Smi::FromInt(line_ends[i]));
9202 }
9203 return array;
9204 }
9205
9206
8907 // Compares the contents of two strings by reading and comparing 9207 // Compares the contents of two strings by reading and comparing
8908 // int-sized blocks of characters. 9208 // int-sized blocks of characters.
8909 template <typename Char> 9209 template <typename Char>
8910 static inline bool CompareRawStringContents(const Char* const a, 9210 static inline bool CompareRawStringContents(const Char* const a,
8911 const Char* const b, 9211 const Char* const b,
8912 int length) { 9212 int length) {
8913 int i = 0; 9213 int i = 0;
8914 #ifndef V8_HOST_CAN_READ_UNALIGNED 9214 #ifndef V8_HOST_CAN_READ_UNALIGNED
8915 // If this architecture isn't comfortable reading unaligned ints 9215 // If this architecture isn't comfortable reading unaligned ints
8916 // then we have to check that the strings are aligned before 9216 // then we have to check that the strings are aligned before
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
10106 CStrVector(to_string)); 10406 CStrVector(to_string));
10107 if (!maybe_string->To(&internalized_to_string)) return maybe_string; 10407 if (!maybe_string->To(&internalized_to_string)) return maybe_string;
10108 } 10408 }
10109 set_to_string(internalized_to_string); 10409 set_to_string(internalized_to_string);
10110 set_to_number(to_number); 10410 set_to_number(to_number);
10111 set_kind(kind); 10411 set_kind(kind);
10112 return this; 10412 return this;
10113 } 10413 }
10114 10414
10115 10415
10416 void Script::InitLineEnds(Handle<Script> script) {
10417 if (!script->line_ends()->IsUndefined()) return;
10418
10419 Isolate* isolate = script->GetIsolate();
10420
10421 if (!script->source()->IsString()) {
10422 ASSERT(script->source()->IsUndefined());
10423 Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0);
10424 script->set_line_ends(*empty);
10425 ASSERT(script->line_ends()->IsFixedArray());
10426 return;
10427 }
10428
10429 Handle<String> src(String::cast(script->source()), isolate);
10430
10431 Handle<FixedArray> array = String::CalculateLineEnds(src, true);
10432
10433 if (*array != isolate->heap()->empty_fixed_array()) {
10434 array->set_map(isolate->heap()->fixed_cow_array_map());
10435 }
10436
10437 script->set_line_ends(*array);
10438 ASSERT(script->line_ends()->IsFixedArray());
10439 }
10440
10441
10442 int Script::GetColumnNumber(Handle<Script> script, int code_pos) {
10443 int line_number = GetLineNumber(script, code_pos);
10444 if (line_number == -1) return -1;
10445
10446 DisallowHeapAllocation no_allocation;
10447 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
10448 line_number = line_number - script->line_offset()->value();
10449 if (line_number == 0) return code_pos + script->column_offset()->value();
10450 int prev_line_end_pos =
10451 Smi::cast(line_ends_array->get(line_number - 1))->value();
10452 return code_pos - (prev_line_end_pos + 1);
10453 }
10454
10455
10456 int Script::GetLineNumberWithArray(int code_pos) {
10457 DisallowHeapAllocation no_allocation;
10458 ASSERT(line_ends()->IsFixedArray());
10459 FixedArray* line_ends_array = FixedArray::cast(line_ends());
10460 int line_ends_len = line_ends_array->length();
10461 if (line_ends_len == 0) return -1;
10462
10463 if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
10464 return line_offset()->value();
10465 }
10466
10467 int left = 0;
10468 int right = line_ends_len;
10469 while (int half = (right - left) / 2) {
10470 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
10471 right -= half;
10472 } else {
10473 left += half;
10474 }
10475 }
10476 return right + line_offset()->value();
10477 }
10478
10479
10480 int Script::GetLineNumber(Handle<Script> script, int code_pos) {
10481 InitLineEnds(script);
10482 return script->GetLineNumberWithArray(code_pos);
10483 }
10484
10485
10486 int Script::GetLineNumber(int code_pos) {
10487 DisallowHeapAllocation no_allocation;
10488 if (!line_ends()->IsUndefined()) return GetLineNumberWithArray(code_pos);
10489
10490 // Slow mode: we do not have line_ends. We have to iterate through source.
10491 if (!source()->IsString()) return -1;
10492
10493 String* source_string = String::cast(source());
10494 int line = 0;
10495 int len = source_string->length();
10496 for (int pos = 0; pos < len; pos++) {
10497 if (pos == code_pos) break;
10498 if (source_string->Get(pos) == '\n') line++;
10499 }
10500 return line;
10501 }
10502
10503
10504 Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) {
10505 Isolate* isolate = script->GetIsolate();
10506 Handle<String> name_or_source_url_key =
10507 isolate->factory()->InternalizeOneByteString(
10508 STATIC_ASCII_VECTOR("nameOrSourceURL"));
10509 Handle<JSObject> script_wrapper = Script::GetWrapper(script);
10510 Handle<Object> property = Object::GetProperty(
10511 script_wrapper, name_or_source_url_key).ToHandleChecked();
10512 ASSERT(property->IsJSFunction());
10513 Handle<JSFunction> method = Handle<JSFunction>::cast(property);
10514 Handle<Object> result;
10515 // Do not check against pending exception, since this function may be called
10516 // when an exception has already been pending.
10517 if (!Execution::TryCall(method, script_wrapper, 0, NULL).ToHandle(&result)) {
10518 return isolate->factory()->undefined_value();
10519 }
10520 return result;
10521 }
10522
10523
10524 // Wrappers for scripts are kept alive and cached in weak global
10525 // handles referred from foreign objects held by the scripts as long as
10526 // they are used. When they are not used anymore, the garbage
10527 // collector will call the weak callback on the global handle
10528 // associated with the wrapper and get rid of both the wrapper and the
10529 // handle.
10530 static void ClearWrapperCache(
10531 const v8::WeakCallbackData<v8::Value, void>& data) {
10532 Object** location = reinterpret_cast<Object**>(data.GetParameter());
10533 JSValue* wrapper = JSValue::cast(*location);
10534 Foreign* foreign = Script::cast(wrapper->value())->wrapper();
10535 ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
10536 foreign->set_foreign_address(0);
10537 GlobalHandles::Destroy(location);
10538 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
10539 isolate->counters()->script_wrappers()->Decrement();
10540 }
10541
10542
10543 Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
10544 if (script->wrapper()->foreign_address() != NULL) {
10545 // Return a handle for the existing script wrapper from the cache.
10546 return Handle<JSValue>(
10547 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
10548 }
10549 Isolate* isolate = script->GetIsolate();
10550 // Construct a new script wrapper.
10551 isolate->counters()->script_wrappers()->Increment();
10552 Handle<JSFunction> constructor = isolate->script_function();
10553 Handle<JSValue> result =
10554 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
10555
10556 result->set_value(*script);
10557
10558 // Create a new weak global handle and use it to cache the wrapper
10559 // for future use. The cache will automatically be cleared by the
10560 // garbage collector when it is not used anymore.
10561 Handle<Object> handle = isolate->global_handles()->Create(*result);
10562 GlobalHandles::MakeWeak(handle.location(),
10563 reinterpret_cast<void*>(handle.location()),
10564 &ClearWrapperCache);
10565 script->wrapper()->set_foreign_address(
10566 reinterpret_cast<Address>(handle.location()));
10567 return result;
10568 }
10569
10570
10116 String* SharedFunctionInfo::DebugName() { 10571 String* SharedFunctionInfo::DebugName() {
10117 Object* n = name(); 10572 Object* n = name();
10118 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); 10573 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name();
10119 return String::cast(n); 10574 return String::cast(n);
10120 } 10575 }
10121 10576
10122 10577
10123 bool SharedFunctionInfo::HasSourceCode() { 10578 bool SharedFunctionInfo::HasSourceCode() {
10124 return !script()->IsUndefined() && 10579 return !script()->IsUndefined() &&
10125 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); 10580 !reinterpret_cast<Script*>(script())->source()->IsUndefined();
(...skipping 3307 matching lines...) Expand 10 before | Expand all | Expand 10 after
13433 result_internal->VerifyApiCallResultType(); 13888 result_internal->VerifyApiCallResultType();
13434 // Rebox handle before return. 13889 // Rebox handle before return.
13435 return handle(*result_internal, isolate); 13890 return handle(*result_internal, isolate);
13436 } 13891 }
13437 } 13892 }
13438 13893
13439 return GetPropertyPostInterceptor(object, receiver, name, attributes); 13894 return GetPropertyPostInterceptor(object, receiver, name, attributes);
13440 } 13895 }
13441 13896
13442 13897
13898 // Compute the property keys from the interceptor.
13899 // TODO(rossberg): support symbols in API, and filter here if needed.
13900 MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor(
13901 Handle<JSObject> object, Handle<JSReceiver> receiver) {
13902 Isolate* isolate = receiver->GetIsolate();
13903 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
13904 PropertyCallbackArguments
13905 args(isolate, interceptor->data(), *receiver, *object);
13906 v8::Handle<v8::Array> result;
13907 if (!interceptor->enumerator()->IsUndefined()) {
13908 v8::NamedPropertyEnumeratorCallback enum_fun =
13909 v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
13910 interceptor->enumerator());
13911 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
13912 result = args.Call(enum_fun);
13913 }
13914 if (result.IsEmpty()) return MaybeHandle<JSArray>();
13915 #if ENABLE_EXTRA_CHECKS
13916 CHECK(v8::Utils::OpenHandle(*result)->IsJSArray());
13917 #endif
13918 return v8::Utils::OpenHandle(*result);
13919 }
13920
13921
13922 // Compute the element keys from the interceptor.
13923 MaybeHandle<JSArray> JSObject::GetKeysForIndexedInterceptor(
13924 Handle<JSObject> object, Handle<JSReceiver> receiver) {
13925 Isolate* isolate = receiver->GetIsolate();
13926 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
13927 PropertyCallbackArguments
13928 args(isolate, interceptor->data(), *receiver, *object);
13929 v8::Handle<v8::Array> result;
13930 if (!interceptor->enumerator()->IsUndefined()) {
13931 v8::IndexedPropertyEnumeratorCallback enum_fun =
13932 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>(
13933 interceptor->enumerator());
13934 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
13935 result = args.Call(enum_fun);
13936 }
13937 if (result.IsEmpty()) return MaybeHandle<JSArray>();
13938 #if ENABLE_EXTRA_CHECKS
13939 CHECK(v8::Utils::OpenHandle(*result)->IsJSArray());
13940 #endif
13941 return v8::Utils::OpenHandle(*result);
13942 }
13943
13944
13443 bool JSObject::HasRealNamedProperty(Handle<JSObject> object, 13945 bool JSObject::HasRealNamedProperty(Handle<JSObject> object,
13444 Handle<Name> key) { 13946 Handle<Name> key) {
13445 Isolate* isolate = object->GetIsolate(); 13947 Isolate* isolate = object->GetIsolate();
13446 SealHandleScope shs(isolate); 13948 SealHandleScope shs(isolate);
13447 // Check access rights if needed. 13949 // Check access rights if needed.
13448 if (object->IsAccessCheckNeeded()) { 13950 if (object->IsAccessCheckNeeded()) {
13449 if (!isolate->MayNamedAccess(object, key, v8::ACCESS_HAS)) { 13951 if (!isolate->MayNamedAccess(object, key, v8::ACCESS_HAS)) {
13450 isolate->ReportFailedAccessCheck(object, v8::ACCESS_HAS); 13952 isolate->ReportFailedAccessCheck(object, v8::ACCESS_HAS);
13451 // TODO(yangguo): Issue 3269, check for scheduled exception missing? 13953 // TODO(yangguo): Issue 3269, check for scheduled exception missing?
13452 return false; 13954 return false;
(...skipping 3143 matching lines...) Expand 10 before | Expand all | Expand 10 after
16596 #define ERROR_MESSAGES_TEXTS(C, T) T, 17098 #define ERROR_MESSAGES_TEXTS(C, T) T,
16597 static const char* error_messages_[] = { 17099 static const char* error_messages_[] = {
16598 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17100 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16599 }; 17101 };
16600 #undef ERROR_MESSAGES_TEXTS 17102 #undef ERROR_MESSAGES_TEXTS
16601 return error_messages_[reason]; 17103 return error_messages_[reason];
16602 } 17104 }
16603 17105
16604 17106
16605 } } // namespace v8::internal 17107 } } // namespace v8::internal
OLDNEW
« src/compiler.cc ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698