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

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

Powered by Google App Engine
This is Rietveld 408576698