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

Side by Side Diff: src/runtime.cc

Issue 10105026: Version 3.10.3 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 8 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/runtime.h ('k') | src/scanner.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 // Traverse the name/value pairs and set the properties. 1282 // Traverse the name/value pairs and set the properties.
1283 int length = pairs->length(); 1283 int length = pairs->length();
1284 for (int i = 0; i < length; i += 2) { 1284 for (int i = 0; i < length; i += 2) {
1285 HandleScope scope(isolate); 1285 HandleScope scope(isolate);
1286 Handle<String> name(String::cast(pairs->get(i))); 1286 Handle<String> name(String::cast(pairs->get(i)));
1287 Handle<Object> value(pairs->get(i + 1), isolate); 1287 Handle<Object> value(pairs->get(i + 1), isolate);
1288 1288
1289 // We have to declare a global const property. To capture we only 1289 // We have to declare a global const property. To capture we only
1290 // assign to it when evaluating the assignment for "const x = 1290 // assign to it when evaluating the assignment for "const x =
1291 // <expr>" the initial value is the hole. 1291 // <expr>" the initial value is the hole.
1292 bool is_const_property = value->IsTheHole(); 1292 bool is_var = value->IsUndefined();
1293 bool is_function_declaration = false; 1293 bool is_const = value->IsTheHole();
1294 if (value->IsUndefined() || is_const_property) { 1294 bool is_function = value->IsSharedFunctionInfo();
1295 bool is_module = value->IsJSModule();
1296 ASSERT(is_var + is_const + is_function + is_module == 1);
1297
1298 if (is_var || is_const) {
1295 // Lookup the property in the global object, and don't set the 1299 // Lookup the property in the global object, and don't set the
1296 // value of the variable if the property is already there. 1300 // value of the variable if the property is already there.
1301 // Do the lookup locally only, see ES5 errata.
1297 LookupResult lookup(isolate); 1302 LookupResult lookup(isolate);
1298 global->Lookup(*name, &lookup); 1303 global->LocalLookup(*name, &lookup);
1299 if (lookup.IsProperty()) { 1304 if (lookup.IsProperty()) {
1300 // We found an existing property. Unless it was an interceptor 1305 // We found an existing property. Unless it was an interceptor
1301 // that claims the property is absent, skip this declaration. 1306 // that claims the property is absent, skip this declaration.
1302 if (lookup.type() != INTERCEPTOR) { 1307 if (lookup.type() != INTERCEPTOR) continue;
1303 continue;
1304 }
1305 PropertyAttributes attributes = global->GetPropertyAttribute(*name); 1308 PropertyAttributes attributes = global->GetPropertyAttribute(*name);
1306 if (attributes != ABSENT) { 1309 if (attributes != ABSENT) continue;
1307 continue;
1308 }
1309 // Fall-through and introduce the absent property by using 1310 // Fall-through and introduce the absent property by using
1310 // SetProperty. 1311 // SetProperty.
1311 } 1312 }
1312 } else { 1313 } else if (is_function) {
1313 is_function_declaration = true;
1314 // Copy the function and update its context. Use it as value. 1314 // Copy the function and update its context. Use it as value.
1315 Handle<SharedFunctionInfo> shared = 1315 Handle<SharedFunctionInfo> shared =
1316 Handle<SharedFunctionInfo>::cast(value); 1316 Handle<SharedFunctionInfo>::cast(value);
1317 Handle<JSFunction> function = 1317 Handle<JSFunction> function =
1318 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 1318 isolate->factory()->NewFunctionFromSharedFunctionInfo(
1319 context, 1319 shared, context, TENURED);
1320 TENURED);
1321 value = function; 1320 value = function;
1322 } 1321 }
1323 1322
1324 LookupResult lookup(isolate); 1323 LookupResult lookup(isolate);
1325 global->LocalLookup(*name, &lookup); 1324 global->LocalLookup(*name, &lookup);
1326 1325
1327 // Compute the property attributes. According to ECMA-262, section 1326 // Compute the property attributes. According to ECMA-262,
1328 // 13, page 71, the property must be read-only and 1327 // the property must be non-configurable except in eval.
1329 // non-deletable. However, neither SpiderMonkey nor KJS creates the
1330 // property as read-only, so we don't either.
1331 int attr = NONE; 1328 int attr = NONE;
1332 if (!DeclareGlobalsEvalFlag::decode(flags)) { 1329 bool is_eval = DeclareGlobalsEvalFlag::decode(flags);
1330 if (!is_eval || is_module) {
1333 attr |= DONT_DELETE; 1331 attr |= DONT_DELETE;
1334 } 1332 }
1335 bool is_native = DeclareGlobalsNativeFlag::decode(flags); 1333 bool is_native = DeclareGlobalsNativeFlag::decode(flags);
1336 if (is_const_property || (is_native && is_function_declaration)) { 1334 if (is_const || is_module || (is_native && is_function)) {
1337 attr |= READ_ONLY; 1335 attr |= READ_ONLY;
1338 } 1336 }
1339 1337
1340 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags); 1338 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
1341 1339
1342 // Safari does not allow the invocation of callback setters for 1340 if (!lookup.IsProperty() || is_function || is_module) {
1343 // function declarations. To mimic this behavior, we do not allow 1341 // If the local property exists, check that we can reconfigure it
1344 // the invocation of setters for function values. This makes a 1342 // as required for function declarations.
1345 // difference for global functions with the same names as event 1343 if (lookup.IsProperty() && lookup.IsDontDelete()) {
1346 // handlers such as "function onload() {}". Firefox does call the 1344 if (lookup.IsReadOnly() || lookup.IsDontEnum() ||
1347 // onload setter in those case and Safari does not. We follow 1345 lookup.type() == CALLBACKS) {
1348 // Safari for compatibility. 1346 return ThrowRedeclarationError(
1349 if (is_function_declaration) { 1347 isolate, is_function ? "function" : "module", name);
1350 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) {
1351 // Do not overwrite READ_ONLY properties.
1352 if (lookup.GetAttributes() & READ_ONLY) {
1353 if (language_mode != CLASSIC_MODE) {
1354 Handle<Object> args[] = { name };
1355 return isolate->Throw(*isolate->factory()->NewTypeError(
1356 "strict_cannot_assign", HandleVector(args, ARRAY_SIZE(args))));
1357 }
1358 continue;
1359 } 1348 }
1360 // Do not change DONT_DELETE to false from true. 1349 // If the existing property is not configurable, keep its attributes.
1361 attr |= lookup.GetAttributes() & DONT_DELETE; 1350 attr = lookup.GetAttributes();
1362 } 1351 }
1363 PropertyAttributes attributes = static_cast<PropertyAttributes>(attr); 1352 // Define or redefine own property.
1364 1353 RETURN_IF_EMPTY_HANDLE(isolate,
1365 RETURN_IF_EMPTY_HANDLE( 1354 JSObject::SetLocalPropertyIgnoreAttributes(
1366 isolate, 1355 global, name, value, static_cast<PropertyAttributes>(attr)));
1367 JSObject::SetLocalPropertyIgnoreAttributes(global, name, value,
1368 attributes));
1369 } else { 1356 } else {
1370 RETURN_IF_EMPTY_HANDLE( 1357 // Do a [[Put]] on the existing (own) property.
1371 isolate, 1358 RETURN_IF_EMPTY_HANDLE(isolate,
1372 JSReceiver::SetProperty(global, name, value, 1359 JSObject::SetProperty(
1373 static_cast<PropertyAttributes>(attr), 1360 global, name, value, static_cast<PropertyAttributes>(attr),
1374 language_mode == CLASSIC_MODE 1361 language_mode == CLASSIC_MODE ? kNonStrictMode : kStrictMode));
1375 ? kNonStrictMode : kStrictMode));
1376 } 1362 }
1377 } 1363 }
1378 1364
1379 ASSERT(!isolate->has_pending_exception()); 1365 ASSERT(!isolate->has_pending_exception());
1380 return isolate->heap()->undefined_value(); 1366 return isolate->heap()->undefined_value();
1381 } 1367 }
1382 1368
1383 1369
1384 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { 1370 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) {
1385 HandleScope scope(isolate); 1371 HandleScope scope(isolate);
(...skipping 12 matching lines...) Expand all
1398 1384
1399 int index; 1385 int index;
1400 PropertyAttributes attributes; 1386 PropertyAttributes attributes;
1401 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; 1387 ContextLookupFlags flags = DONT_FOLLOW_CHAINS;
1402 BindingFlags binding_flags; 1388 BindingFlags binding_flags;
1403 Handle<Object> holder = 1389 Handle<Object> holder =
1404 context->Lookup(name, flags, &index, &attributes, &binding_flags); 1390 context->Lookup(name, flags, &index, &attributes, &binding_flags);
1405 1391
1406 if (attributes != ABSENT) { 1392 if (attributes != ABSENT) {
1407 // The name was declared before; check for conflicting re-declarations. 1393 // The name was declared before; check for conflicting re-declarations.
1394 // Note: this is actually inconsistent with what happens for globals (where
1395 // we silently ignore such declarations).
1408 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) { 1396 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) {
1409 // Functions are not read-only. 1397 // Functions are not read-only.
1410 ASSERT(mode != READ_ONLY || initial_value->IsTheHole()); 1398 ASSERT(mode != READ_ONLY || initial_value->IsTheHole());
1411 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var"; 1399 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var";
1412 return ThrowRedeclarationError(isolate, type, name); 1400 return ThrowRedeclarationError(isolate, type, name);
1413 } 1401 }
1414 1402
1415 // Initialize it if necessary. 1403 // Initialize it if necessary.
1416 if (*initial_value != NULL) { 1404 if (*initial_value != NULL) {
1417 if (index >= 0) { 1405 if (index >= 0) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 // SetProperty and no setters are invoked for those since they are 1448 // SetProperty and no setters are invoked for those since they are
1461 // not real JSObjects. 1449 // not real JSObjects.
1462 if (initial_value->IsTheHole() && 1450 if (initial_value->IsTheHole() &&
1463 !object->IsJSContextExtensionObject()) { 1451 !object->IsJSContextExtensionObject()) {
1464 LookupResult lookup(isolate); 1452 LookupResult lookup(isolate);
1465 object->Lookup(*name, &lookup); 1453 object->Lookup(*name, &lookup);
1466 if (lookup.IsFound() && (lookup.type() == CALLBACKS)) { 1454 if (lookup.IsFound() && (lookup.type() == CALLBACKS)) {
1467 return ThrowRedeclarationError(isolate, "const", name); 1455 return ThrowRedeclarationError(isolate, "const", name);
1468 } 1456 }
1469 } 1457 }
1470 RETURN_IF_EMPTY_HANDLE( 1458 if (object->IsJSGlobalObject()) {
1471 isolate, 1459 // Define own property on the global object.
1472 JSReceiver::SetProperty(object, name, value, mode, kNonStrictMode)); 1460 RETURN_IF_EMPTY_HANDLE(isolate,
1461 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode));
1462 } else {
1463 RETURN_IF_EMPTY_HANDLE(isolate,
1464 JSReceiver::SetProperty(object, name, value, mode, kNonStrictMode));
1465 }
1473 } 1466 }
1474 1467
1475 return isolate->heap()->undefined_value(); 1468 return isolate->heap()->undefined_value();
1476 } 1469 }
1477 1470
1478 1471
1479 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) { 1472 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
1480 NoHandleAllocation nha; 1473 NoHandleAllocation nha;
1481 // args[0] == name 1474 // args[0] == name
1482 // args[1] == language_mode 1475 // args[1] == language_mode
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 MaybeObject* maybe_name = 2087 MaybeObject* maybe_name =
2095 isolate->heap()->AllocateStringFromAscii(CStrVector("prototype")); 2088 isolate->heap()->AllocateStringFromAscii(CStrVector("prototype"));
2096 String* name; 2089 String* name;
2097 if (!maybe_name->To(&name)) return maybe_name; 2090 if (!maybe_name->To(&name)) return maybe_name;
2098 2091
2099 if (function->HasFastProperties()) { 2092 if (function->HasFastProperties()) {
2100 // Construct a new field descriptor with updated attributes. 2093 // Construct a new field descriptor with updated attributes.
2101 DescriptorArray* instance_desc = function->map()->instance_descriptors(); 2094 DescriptorArray* instance_desc = function->map()->instance_descriptors();
2102 int index = instance_desc->Search(name); 2095 int index = instance_desc->Search(name);
2103 ASSERT(index != DescriptorArray::kNotFound); 2096 ASSERT(index != DescriptorArray::kNotFound);
2104 PropertyDetails details(instance_desc->GetDetails(index)); 2097 PropertyDetails details = instance_desc->GetDetails(index);
2105 CallbacksDescriptor new_desc(name, 2098 CallbacksDescriptor new_desc(name,
2106 instance_desc->GetValue(index), 2099 instance_desc->GetValue(index),
2107 static_cast<PropertyAttributes>(details.attributes() | READ_ONLY), 2100 static_cast<PropertyAttributes>(details.attributes() | READ_ONLY),
2108 details.index()); 2101 details.index());
2109 // Construct a new field descriptors array containing the new descriptor. 2102 // Construct a new field descriptors array containing the new descriptor.
2110 Object* descriptors_unchecked; 2103 Object* descriptors_unchecked;
2111 { MaybeObject* maybe_descriptors_unchecked = 2104 { MaybeObject* maybe_descriptors_unchecked =
2112 instance_desc->CopyInsert(&new_desc, REMOVE_TRANSITIONS); 2105 instance_desc->CopyInsert(&new_desc, REMOVE_TRANSITIONS);
2113 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) { 2106 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) {
2114 return maybe_descriptors_unchecked; 2107 return maybe_descriptors_unchecked;
(...skipping 6483 matching lines...) Expand 10 before | Expand all | Expand 10 after
8598 MaybeObject* maybe_context = 8591 MaybeObject* maybe_context =
8599 isolate->heap()->AllocateBlockContext(function, 8592 isolate->heap()->AllocateBlockContext(function,
8600 isolate->context(), 8593 isolate->context(),
8601 scope_info); 8594 scope_info);
8602 if (!maybe_context->To(&context)) return maybe_context; 8595 if (!maybe_context->To(&context)) return maybe_context;
8603 isolate->set_context(context); 8596 isolate->set_context(context);
8604 return context; 8597 return context;
8605 } 8598 }
8606 8599
8607 8600
8601 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushModuleContext) {
8602 NoHandleAllocation ha;
8603 ASSERT(args.length() == 2);
8604 CONVERT_ARG_CHECKED(ScopeInfo, scope_info, 0);
8605 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 1);
8606
8607 Context* context;
8608 MaybeObject* maybe_context =
8609 isolate->heap()->AllocateModuleContext(isolate->context(),
8610 scope_info);
8611 if (!maybe_context->To(&context)) return maybe_context;
8612 // Also initialize the context slot of the instance object.
8613 instance->set_context(context);
8614 isolate->set_context(context);
8615
8616 return context;
8617 }
8618
8619
8608 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { 8620 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) {
8609 HandleScope scope(isolate); 8621 HandleScope scope(isolate);
8610 ASSERT(args.length() == 2); 8622 ASSERT(args.length() == 2);
8611 8623
8612 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0); 8624 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0);
8613 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); 8625 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
8614 8626
8615 int index; 8627 int index;
8616 PropertyAttributes attributes; 8628 PropertyAttributes attributes;
8617 ContextLookupFlags flags = FOLLOW_CHAINS; 8629 ContextLookupFlags flags = FOLLOW_CHAINS;
(...skipping 4736 matching lines...) Expand 10 before | Expand all | Expand 10 after
13354 // Handle last resort GC and make sure to allow future allocations 13366 // Handle last resort GC and make sure to allow future allocations
13355 // to grow the heap without causing GCs (if possible). 13367 // to grow the heap without causing GCs (if possible).
13356 isolate->counters()->gc_last_resort_from_js()->Increment(); 13368 isolate->counters()->gc_last_resort_from_js()->Increment();
13357 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13369 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13358 "Runtime::PerformGC"); 13370 "Runtime::PerformGC");
13359 } 13371 }
13360 } 13372 }
13361 13373
13362 13374
13363 } } // namespace v8::internal 13375 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698