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

Side by Side Diff: src/ic.cc

Issue 6992072: Implement set trap for proxies, and revamp class hierarchy in preparation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Renamed range constants for InstanceType enum. Created 9 years, 7 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 if (!lookup->IsPropertyOrTransition() || !lookup->IsCacheable()) return false; 1336 if (!lookup->IsPropertyOrTransition() || !lookup->IsCacheable()) return false;
1337 1337
1338 // If the property is read-only, we leave the IC in its current 1338 // If the property is read-only, we leave the IC in its current
1339 // state. 1339 // state.
1340 if (lookup->IsReadOnly()) return false; 1340 if (lookup->IsReadOnly()) return false;
1341 1341
1342 return true; 1342 return true;
1343 } 1343 }
1344 1344
1345 1345
1346 static bool LookupForWrite(JSObject* object, 1346 static bool LookupForWrite(JSReceiver* receiver,
1347 String* name, 1347 String* name,
1348 LookupResult* lookup) { 1348 LookupResult* lookup) {
1349 object->LocalLookup(name, lookup); 1349 receiver->LocalLookup(name, lookup);
1350 if (!StoreICableLookup(lookup)) { 1350 if (!StoreICableLookup(lookup)) {
1351 return false; 1351 return false;
1352 } 1352 }
1353 1353
1354 if (lookup->type() == INTERCEPTOR) { 1354 if (lookup->type() == INTERCEPTOR) {
1355 JSObject* object = JSObject::cast(receiver);
1355 if (object->GetNamedInterceptor()->setter()->IsUndefined()) { 1356 if (object->GetNamedInterceptor()->setter()->IsUndefined()) {
1356 object->LocalLookupRealNamedProperty(name, lookup); 1357 object->LocalLookupRealNamedProperty(name, lookup);
1357 return StoreICableLookup(lookup); 1358 return StoreICableLookup(lookup);
1358 } 1359 }
1359 } 1360 }
1360 1361
1361 return true; 1362 return true;
1362 } 1363 }
1363 1364
1364 1365
1365 MaybeObject* StoreIC::Store(State state, 1366 MaybeObject* StoreIC::Store(State state,
1366 StrictModeFlag strict_mode, 1367 StrictModeFlag strict_mode,
1367 Handle<Object> object, 1368 Handle<Object> object,
1368 Handle<String> name, 1369 Handle<String> name,
1369 Handle<Object> value) { 1370 Handle<Object> value) {
1370 // If the object is undefined or null it's illegal to try to set any 1371 // If the object is undefined or null it's illegal to try to set any
1371 // properties on it; throw a TypeError in that case. 1372 // properties on it; throw a TypeError in that case.
1372 if (object->IsUndefined() || object->IsNull()) { 1373 if (object->IsUndefined() || object->IsNull()) {
1373 return TypeError("non_object_property_store", object, name); 1374 return TypeError("non_object_property_store", object, name);
1374 } 1375 }
1375 1376
1376 if (!object->IsJSObject()) { 1377 if (!object->IsJSReceiver()) {
1377 // The length property of string values is read-only. Throw in strict mode. 1378 // The length property of string values is read-only. Throw in strict mode.
1378 if (strict_mode == kStrictMode && object->IsString() && 1379 if (strict_mode == kStrictMode && object->IsString() &&
1379 name->Equals(isolate()->heap()->length_symbol())) { 1380 name->Equals(isolate()->heap()->length_symbol())) {
1380 return TypeError("strict_read_only_property", object, name); 1381 return TypeError("strict_read_only_property", object, name);
1381 } 1382 }
1382 // Ignore stores where the receiver is not a JSObject. 1383 // Ignore stores where the receiver is not a JSObject.
1383 return *value; 1384 return *value;
1384 } 1385 }
1385 1386
1387 // Handle proxies.
1388 if (object->IsJSProxy()) {
1389 HandleScope scope(isolate());
Kevin Millikin (Chromium) 2011/05/30 16:32:29 The handle scope should not be needed here.
rossberg 2011/05/31 14:50:24 Done.
1390 return JSReceiver::cast(*object)->
1391 SetProperty(*name, *value, NONE, strict_mode);
1392 }
1393
1386 Handle<JSObject> receiver = Handle<JSObject>::cast(object); 1394 Handle<JSObject> receiver = Handle<JSObject>::cast(object);
1387 1395
1388 // Check if the given name is an array index. 1396 // Check if the given name is an array index.
1389 uint32_t index; 1397 uint32_t index;
1390 if (name->AsArrayIndex(&index)) { 1398 if (name->AsArrayIndex(&index)) {
1391 HandleScope scope(isolate()); 1399 HandleScope scope(isolate());
1392 Handle<Object> result = SetElement(receiver, index, value, strict_mode); 1400 Handle<Object> result = SetElement(receiver, index, value, strict_mode);
1393 if (result.is_null()) return Failure::Exception(); 1401 if (result.is_null()) return Failure::Exception();
1394 return *value; 1402 return *value;
1395 } 1403 }
1396 1404
1397 // Use specialized code for setting the length of arrays. 1405 // Use specialized code for setting the length of arrays.
1398 if (receiver->IsJSArray() 1406 if (receiver->IsJSArray()
1399 && name->Equals(isolate()->heap()->length_symbol()) 1407 && name->Equals(isolate()->heap()->length_symbol())
1400 && receiver->AllowsSetElementsLength()) { 1408 && JSArray::cast(*receiver)->AllowsSetElementsLength()) {
1401 #ifdef DEBUG 1409 #ifdef DEBUG
1402 if (FLAG_trace_ic) PrintF("[StoreIC : +#length /array]\n"); 1410 if (FLAG_trace_ic) PrintF("[StoreIC : +#length /array]\n");
1403 #endif 1411 #endif
1404 Builtins::Name target = (strict_mode == kStrictMode) 1412 Builtins::Name target = (strict_mode == kStrictMode)
1405 ? Builtins::kStoreIC_ArrayLength_Strict 1413 ? Builtins::kStoreIC_ArrayLength_Strict
1406 : Builtins::kStoreIC_ArrayLength; 1414 : Builtins::kStoreIC_ArrayLength;
1407 set_target(isolate()->builtins()->builtin(target)); 1415 set_target(isolate()->builtins()->builtin(target));
1408 return receiver->SetProperty(*name, *value, NONE, strict_mode); 1416 return receiver->SetProperty(*name, *value, NONE, strict_mode);
1409 } 1417 }
1410 1418
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2557 #undef ADDR 2565 #undef ADDR
2558 }; 2566 };
2559 2567
2560 2568
2561 Address IC::AddressFromUtilityId(IC::UtilityId id) { 2569 Address IC::AddressFromUtilityId(IC::UtilityId id) {
2562 return IC_utilities[id]; 2570 return IC_utilities[id];
2563 } 2571 }
2564 2572
2565 2573
2566 } } // namespace v8::internal 2574 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698