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

Side by Side Diff: src/runtime.cc

Issue 6624085: [Isolates] Merge 7051:7083 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.cc ('k') | src/scopes.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // simple object literal. 337 // simple object literal.
338 Handle<FixedArray> array = Handle<FixedArray>::cast(value); 338 Handle<FixedArray> array = Handle<FixedArray>::cast(value);
339 value = CreateLiteralBoilerplate(isolate, literals, array); 339 value = CreateLiteralBoilerplate(isolate, literals, array);
340 if (value.is_null()) return value; 340 if (value.is_null()) return value;
341 } 341 }
342 Handle<Object> result; 342 Handle<Object> result;
343 uint32_t element_index = 0; 343 uint32_t element_index = 0;
344 if (key->IsSymbol()) { 344 if (key->IsSymbol()) {
345 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { 345 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) {
346 // Array index as string (uint32). 346 // Array index as string (uint32).
347 result = SetOwnElement(boilerplate, element_index, value); 347 result = SetOwnElement(boilerplate,
348 element_index,
349 value,
350 kNonStrictMode);
348 } else { 351 } else {
349 Handle<String> name(String::cast(*key)); 352 Handle<String> name(String::cast(*key));
350 ASSERT(!name->AsArrayIndex(&element_index)); 353 ASSERT(!name->AsArrayIndex(&element_index));
351 result = SetLocalPropertyIgnoreAttributes(boilerplate, name, 354 result = SetLocalPropertyIgnoreAttributes(boilerplate, name,
352 value, NONE); 355 value, NONE);
353 } 356 }
354 } else if (key->ToArrayIndex(&element_index)) { 357 } else if (key->ToArrayIndex(&element_index)) {
355 // Array index (uint32). 358 // Array index (uint32).
356 result = SetOwnElement(boilerplate, element_index, value); 359 result = SetOwnElement(boilerplate,
360 element_index,
361 value,
362 kNonStrictMode);
357 } else { 363 } else {
358 // Non-uint32 number. 364 // Non-uint32 number.
359 ASSERT(key->IsNumber()); 365 ASSERT(key->IsNumber());
360 double num = key->Number(); 366 double num = key->Number();
361 char arr[100]; 367 char arr[100];
362 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 368 Vector<char> buffer(arr, ARRAY_SIZE(arr));
363 const char* str = DoubleToCString(num, buffer); 369 const char* str = DoubleToCString(num, buffer);
364 Handle<String> name = 370 Handle<String> name =
365 isolate->factory()->NewStringFromAscii(CStrVector(str)); 371 isolate->factory()->NewStringFromAscii(CStrVector(str));
366 result = SetLocalPropertyIgnoreAttributes(boilerplate, name, 372 result = SetLocalPropertyIgnoreAttributes(boilerplate, name,
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 // the function context or the arguments object. 1238 // the function context or the arguments object.
1233 if (holder->IsContext()) { 1239 if (holder->IsContext()) {
1234 ASSERT(holder.is_identical_to(context)); 1240 ASSERT(holder.is_identical_to(context));
1235 if (((attributes & READ_ONLY) == 0) || 1241 if (((attributes & READ_ONLY) == 0) ||
1236 context->get(index)->IsTheHole()) { 1242 context->get(index)->IsTheHole()) {
1237 context->set(index, *initial_value); 1243 context->set(index, *initial_value);
1238 } 1244 }
1239 } else { 1245 } else {
1240 // The holder is an arguments object. 1246 // The holder is an arguments object.
1241 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); 1247 Handle<JSObject> arguments(Handle<JSObject>::cast(holder));
1242 Handle<Object> result = SetElement(arguments, index, initial_value); 1248 Handle<Object> result = SetElement(arguments, index, initial_value,
1249 kNonStrictMode);
1243 if (result.is_null()) return Failure::Exception(); 1250 if (result.is_null()) return Failure::Exception();
1244 } 1251 }
1245 } else { 1252 } else {
1246 // Slow case: The property is not in the FixedArray part of the context. 1253 // Slow case: The property is not in the FixedArray part of the context.
1247 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); 1254 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder);
1248 RETURN_IF_EMPTY_HANDLE( 1255 RETURN_IF_EMPTY_HANDLE(
1249 isolate, 1256 isolate,
1250 SetProperty(context_ext, name, initial_value, 1257 SetProperty(context_ext, name, initial_value,
1251 mode, kNonStrictMode)); 1258 mode, kNonStrictMode));
1252 } 1259 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 // should have been a const redeclaration error when declaring 1532 // should have been a const redeclaration error when declaring
1526 // the const property. 1533 // the const property.
1527 ASSERT(!holder.is_identical_to(context)); 1534 ASSERT(!holder.is_identical_to(context));
1528 if ((attributes & READ_ONLY) == 0) { 1535 if ((attributes & READ_ONLY) == 0) {
1529 Handle<Context>::cast(holder)->set(index, *value); 1536 Handle<Context>::cast(holder)->set(index, *value);
1530 } 1537 }
1531 } else { 1538 } else {
1532 // The holder is an arguments object. 1539 // The holder is an arguments object.
1533 ASSERT((attributes & READ_ONLY) == 0); 1540 ASSERT((attributes & READ_ONLY) == 0);
1534 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); 1541 Handle<JSObject> arguments(Handle<JSObject>::cast(holder));
1535 RETURN_IF_EMPTY_HANDLE(isolate, SetElement(arguments, index, value)); 1542 RETURN_IF_EMPTY_HANDLE(
1543 isolate,
1544 SetElement(arguments, index, value, kNonStrictMode));
1536 } 1545 }
1537 return *value; 1546 return *value;
1538 } 1547 }
1539 1548
1540 // The property could not be found, we introduce it in the global 1549 // The property could not be found, we introduce it in the global
1541 // context. 1550 // context.
1542 if (attributes == ABSENT) { 1551 if (attributes == ABSENT) {
1543 Handle<JSObject> global = Handle<JSObject>( 1552 Handle<JSObject> global = Handle<JSObject>(
1544 isolate->context()->global()); 1553 isolate->context()->global());
1545 // Strict mode not needed (const disallowed in strict mode). 1554 // Strict mode not needed (const disallowed in strict mode).
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3980 // of a string using [] notation. We need to support this too in 3989 // of a string using [] notation. We need to support this too in
3981 // JavaScript. 3990 // JavaScript.
3982 // In the case of a String object we just need to redirect the assignment to 3991 // In the case of a String object we just need to redirect the assignment to
3983 // the underlying string if the index is in range. Since the underlying 3992 // the underlying string if the index is in range. Since the underlying
3984 // string does nothing with the assignment then we can ignore such 3993 // string does nothing with the assignment then we can ignore such
3985 // assignments. 3994 // assignments.
3986 if (js_object->IsStringObjectWithCharacterAt(index)) { 3995 if (js_object->IsStringObjectWithCharacterAt(index)) {
3987 return *value; 3996 return *value;
3988 } 3997 }
3989 3998
3990 // TODO(1220): Implement SetElement strict mode. 3999 Handle<Object> result = SetElement(js_object, index, value, strict_mode);
3991 Handle<Object> result = SetElement(js_object, index, value);
3992 if (result.is_null()) return Failure::Exception(); 4000 if (result.is_null()) return Failure::Exception();
3993 return *value; 4001 return *value;
3994 } 4002 }
3995 4003
3996 if (key->IsString()) { 4004 if (key->IsString()) {
3997 Handle<Object> result; 4005 Handle<Object> result;
3998 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { 4006 if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
3999 result = SetElement(js_object, index, value); 4007 result = SetElement(js_object, index, value, strict_mode);
4000 } else { 4008 } else {
4001 Handle<String> key_string = Handle<String>::cast(key); 4009 Handle<String> key_string = Handle<String>::cast(key);
4002 key_string->TryFlatten(); 4010 key_string->TryFlatten();
4003 result = SetProperty(js_object, key_string, value, attr, strict_mode); 4011 result = SetProperty(js_object, key_string, value, attr, strict_mode);
4004 } 4012 }
4005 if (result.is_null()) return Failure::Exception(); 4013 if (result.is_null()) return Failure::Exception();
4006 return *value; 4014 return *value;
4007 } 4015 }
4008 4016
4009 // Call-back into JavaScript to convert the key to a string. 4017 // Call-back into JavaScript to convert the key to a string.
4010 bool has_pending_exception = false; 4018 bool has_pending_exception = false;
4011 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 4019 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
4012 if (has_pending_exception) return Failure::Exception(); 4020 if (has_pending_exception) return Failure::Exception();
4013 Handle<String> name = Handle<String>::cast(converted); 4021 Handle<String> name = Handle<String>::cast(converted);
4014 4022
4015 if (name->AsArrayIndex(&index)) { 4023 if (name->AsArrayIndex(&index)) {
4016 // TODO(1220): Implement SetElement strict mode. 4024 return js_object->SetElement(index, *value, strict_mode);
4017 return js_object->SetElement(index, *value);
4018 } else { 4025 } else {
4019 return js_object->SetProperty(*name, *value, attr, strict_mode); 4026 return js_object->SetProperty(*name, *value, attr, strict_mode);
4020 } 4027 }
4021 } 4028 }
4022 4029
4023 4030
4024 MaybeObject* Runtime::ForceSetObjectProperty(Isolate* isolate, 4031 MaybeObject* Runtime::ForceSetObjectProperty(Isolate* isolate,
4025 Handle<JSObject> js_object, 4032 Handle<JSObject> js_object,
4026 Handle<Object> key, 4033 Handle<Object> key,
4027 Handle<Object> value, 4034 Handle<Object> value,
4028 PropertyAttributes attr) { 4035 PropertyAttributes attr) {
4029 HandleScope scope(isolate); 4036 HandleScope scope(isolate);
4030 4037
4031 // Check if the given key is an array index. 4038 // Check if the given key is an array index.
4032 uint32_t index; 4039 uint32_t index;
4033 if (key->ToArrayIndex(&index)) { 4040 if (key->ToArrayIndex(&index)) {
4034 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 4041 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
4035 // of a string using [] notation. We need to support this too in 4042 // of a string using [] notation. We need to support this too in
4036 // JavaScript. 4043 // JavaScript.
4037 // In the case of a String object we just need to redirect the assignment to 4044 // In the case of a String object we just need to redirect the assignment to
4038 // the underlying string if the index is in range. Since the underlying 4045 // the underlying string if the index is in range. Since the underlying
4039 // string does nothing with the assignment then we can ignore such 4046 // string does nothing with the assignment then we can ignore such
4040 // assignments. 4047 // assignments.
4041 if (js_object->IsStringObjectWithCharacterAt(index)) { 4048 if (js_object->IsStringObjectWithCharacterAt(index)) {
4042 return *value; 4049 return *value;
4043 } 4050 }
4044 4051
4045 return js_object->SetElement(index, *value); 4052 return js_object->SetElement(index, *value, kNonStrictMode);
4046 } 4053 }
4047 4054
4048 if (key->IsString()) { 4055 if (key->IsString()) {
4049 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { 4056 if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
4050 return js_object->SetElement(index, *value); 4057 return js_object->SetElement(index, *value, kNonStrictMode);
4051 } else { 4058 } else {
4052 Handle<String> key_string = Handle<String>::cast(key); 4059 Handle<String> key_string = Handle<String>::cast(key);
4053 key_string->TryFlatten(); 4060 key_string->TryFlatten();
4054 return js_object->SetLocalPropertyIgnoreAttributes(*key_string, 4061 return js_object->SetLocalPropertyIgnoreAttributes(*key_string,
4055 *value, 4062 *value,
4056 attr); 4063 attr);
4057 } 4064 }
4058 } 4065 }
4059 4066
4060 // Call-back into JavaScript to convert the key to a string. 4067 // Call-back into JavaScript to convert the key to a string.
4061 bool has_pending_exception = false; 4068 bool has_pending_exception = false;
4062 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 4069 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
4063 if (has_pending_exception) return Failure::Exception(); 4070 if (has_pending_exception) return Failure::Exception();
4064 Handle<String> name = Handle<String>::cast(converted); 4071 Handle<String> name = Handle<String>::cast(converted);
4065 4072
4066 if (name->AsArrayIndex(&index)) { 4073 if (name->AsArrayIndex(&index)) {
4067 return js_object->SetElement(index, *value); 4074 return js_object->SetElement(index, *value, kNonStrictMode);
4068 } else { 4075 } else {
4069 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); 4076 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr);
4070 } 4077 }
4071 } 4078 }
4072 4079
4073 4080
4074 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, 4081 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate,
4075 Handle<JSObject> js_object, 4082 Handle<JSObject> js_object,
4076 Handle<Object> key) { 4083 Handle<Object> key) {
4077 HandleScope scope(isolate); 4084 HandleScope scope(isolate);
(...skipping 3808 matching lines...) Expand 10 before | Expand all | Expand 10 after
7886 PropertyAttributes attributes; 7893 PropertyAttributes attributes;
7887 ContextLookupFlags flags = FOLLOW_CHAINS; 7894 ContextLookupFlags flags = FOLLOW_CHAINS;
7888 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); 7895 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes);
7889 7896
7890 if (index >= 0) { 7897 if (index >= 0) {
7891 if (holder->IsContext()) { 7898 if (holder->IsContext()) {
7892 // Ignore if read_only variable. 7899 // Ignore if read_only variable.
7893 if ((attributes & READ_ONLY) == 0) { 7900 if ((attributes & READ_ONLY) == 0) {
7894 // Context is a fixed array and set cannot fail. 7901 // Context is a fixed array and set cannot fail.
7895 Context::cast(*holder)->set(index, *value); 7902 Context::cast(*holder)->set(index, *value);
7903 } else if (strict_mode == kStrictMode) {
7904 // Setting read only property in strict mode.
7905 Handle<Object> error =
7906 isolate->factory()->NewTypeError("strict_cannot_assign",
7907 HandleVector(&name, 1));
7908 return isolate->Throw(*error);
7896 } 7909 }
7897 } else { 7910 } else {
7898 ASSERT((attributes & READ_ONLY) == 0); 7911 ASSERT((attributes & READ_ONLY) == 0);
7899 Handle<Object> result = 7912 Handle<Object> result =
7900 SetElement(Handle<JSObject>::cast(holder), index, value); 7913 SetElement(Handle<JSObject>::cast(holder), index, value, strict_mode);
7901 if (result.is_null()) { 7914 if (result.is_null()) {
7902 ASSERT(isolate->has_pending_exception()); 7915 ASSERT(isolate->has_pending_exception());
7903 return Failure::Exception(); 7916 return Failure::Exception();
7904 } 7917 }
7905 } 7918 }
7906 return *value; 7919 return *value;
7907 } 7920 }
7908 7921
7909 // Slow case: The property is not in a FixedArray context. 7922 // Slow case: The property is not in a FixedArray context.
7910 // It is either in an JSObject extension context or it was not found. 7923 // It is either in an JSObject extension context or it was not found.
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
8428 ASSERT(args.length() == 2); 8441 ASSERT(args.length() == 2);
8429 CONVERT_CHECKED(JSArray, array, args[0]); 8442 CONVERT_CHECKED(JSArray, array, args[0]);
8430 CONVERT_CHECKED(JSObject, element, args[1]); 8443 CONVERT_CHECKED(JSObject, element, args[1]);
8431 RUNTIME_ASSERT(array->HasFastElements()); 8444 RUNTIME_ASSERT(array->HasFastElements());
8432 int length = Smi::cast(array->length())->value(); 8445 int length = Smi::cast(array->length())->value();
8433 FixedArray* elements = FixedArray::cast(array->elements()); 8446 FixedArray* elements = FixedArray::cast(array->elements());
8434 for (int i = 0; i < length; i++) { 8447 for (int i = 0; i < length; i++) {
8435 if (elements->get(i) == element) return isolate->heap()->false_value(); 8448 if (elements->get(i) == element) return isolate->heap()->false_value();
8436 } 8449 }
8437 Object* obj; 8450 Object* obj;
8438 { MaybeObject* maybe_obj = array->SetFastElement(length, element); 8451 // Strict not needed. Used for cycle detection in Array join implementation.
8452 { MaybeObject* maybe_obj = array->SetFastElement(length, element,
8453 kNonStrictMode);
8439 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 8454 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
8440 } 8455 }
8441 return isolate->heap()->true_value(); 8456 return isolate->heap()->true_value();
8442 } 8457 }
8443 8458
8444 8459
8445 /** 8460 /**
8446 * A simple visitor visits every element of Array's. 8461 * A simple visitor visits every element of Array's.
8447 * The backend storage can be a fixed array for fast elements case, 8462 * The backend storage can be a fixed array for fast elements case,
8448 * or a dictionary for sparse array. Since Dictionary is a subtype 8463 * or a dictionary for sparse array. Since Dictionary is a subtype
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
9047 || !key2->ToArrayIndex(&index2)) { 9062 || !key2->ToArrayIndex(&index2)) {
9048 return isolate->ThrowIllegalOperation(); 9063 return isolate->ThrowIllegalOperation();
9049 } 9064 }
9050 9065
9051 Handle<JSObject> jsobject = Handle<JSObject>::cast(object); 9066 Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
9052 Handle<Object> tmp1 = GetElement(jsobject, index1); 9067 Handle<Object> tmp1 = GetElement(jsobject, index1);
9053 RETURN_IF_EMPTY_HANDLE(isolate, tmp1); 9068 RETURN_IF_EMPTY_HANDLE(isolate, tmp1);
9054 Handle<Object> tmp2 = GetElement(jsobject, index2); 9069 Handle<Object> tmp2 = GetElement(jsobject, index2);
9055 RETURN_IF_EMPTY_HANDLE(isolate, tmp2); 9070 RETURN_IF_EMPTY_HANDLE(isolate, tmp2);
9056 9071
9057 RETURN_IF_EMPTY_HANDLE(isolate, SetElement(jsobject, index1, tmp2)); 9072 RETURN_IF_EMPTY_HANDLE(isolate,
9058 RETURN_IF_EMPTY_HANDLE(isolate, SetElement(jsobject, index2, tmp1)); 9073 SetElement(jsobject, index1, tmp2, kStrictMode));
9074 RETURN_IF_EMPTY_HANDLE(isolate,
9075 SetElement(jsobject, index2, tmp1, kStrictMode));
9059 9076
9060 return isolate->heap()->undefined_value(); 9077 return isolate->heap()->undefined_value();
9061 } 9078 }
9062 9079
9063 9080
9064 // Returns an array that tells you where in the [0, length) interval an array 9081 // Returns an array that tells you where in the [0, length) interval an array
9065 // might have elements. Can either return keys (positive integers) or 9082 // might have elements. Can either return keys (positive integers) or
9066 // intervals (pair of a negative integer (-start-1) followed by a 9083 // intervals (pair of a negative integer (-start-1) followed by a
9067 // positive (length)) or undefined values. 9084 // positive (length)) or undefined values.
9068 // Intervals can span over some keys that are not in the object. 9085 // Intervals can span over some keys that are not in the object.
(...skipping 3077 matching lines...) Expand 10 before | Expand all | Expand 10 after
12146 } else { 12163 } else {
12147 // Handle last resort GC and make sure to allow future allocations 12164 // Handle last resort GC and make sure to allow future allocations
12148 // to grow the heap without causing GCs (if possible). 12165 // to grow the heap without causing GCs (if possible).
12149 COUNTERS->gc_last_resort_from_js()->Increment(); 12166 COUNTERS->gc_last_resort_from_js()->Increment();
12150 HEAP->CollectAllGarbage(false); 12167 HEAP->CollectAllGarbage(false);
12151 } 12168 }
12152 } 12169 }
12153 12170
12154 12171
12155 } } // namespace v8::internal 12172 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698