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

Side by Side Diff: src/runtime.cc

Issue 9696035: Function declarations shall not overwrite read-only global properties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Michael's comments. Created 8 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 | « no previous file | test/mjsunit/regress/regress-115452.js » ('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 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 // property as read-only, so we don't either. 1329 // property as read-only, so we don't either.
1330 int attr = NONE; 1330 int attr = NONE;
1331 if (!DeclareGlobalsEvalFlag::decode(flags)) { 1331 if (!DeclareGlobalsEvalFlag::decode(flags)) {
1332 attr |= DONT_DELETE; 1332 attr |= DONT_DELETE;
1333 } 1333 }
1334 bool is_native = DeclareGlobalsNativeFlag::decode(flags); 1334 bool is_native = DeclareGlobalsNativeFlag::decode(flags);
1335 if (is_const_property || (is_native && is_function_declaration)) { 1335 if (is_const_property || (is_native && is_function_declaration)) {
1336 attr |= READ_ONLY; 1336 attr |= READ_ONLY;
1337 } 1337 }
1338 1338
1339 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
1340
1339 // Safari does not allow the invocation of callback setters for 1341 // Safari does not allow the invocation of callback setters for
1340 // function declarations. To mimic this behavior, we do not allow 1342 // function declarations. To mimic this behavior, we do not allow
1341 // the invocation of setters for function values. This makes a 1343 // the invocation of setters for function values. This makes a
1342 // difference for global functions with the same names as event 1344 // difference for global functions with the same names as event
1343 // handlers such as "function onload() {}". Firefox does call the 1345 // handlers such as "function onload() {}". Firefox does call the
1344 // onload setter in those case and Safari does not. We follow 1346 // onload setter in those case and Safari does not. We follow
1345 // Safari for compatibility. 1347 // Safari for compatibility.
1346 if (value->IsJSFunction()) { 1348 if (is_function_declaration) {
1347 // Do not change DONT_DELETE to false from true.
1348 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) { 1349 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) {
1350 // Do not overwrite READ_ONLY properties.
1351 if (lookup.GetAttributes() & READ_ONLY) {
1352 if (language_mode != CLASSIC_MODE) {
1353 Handle<Object> args[] = { name };
1354 return isolate->Throw(*isolate->factory()->NewTypeError(
1355 "strict_cannot_assign", HandleVector(args, ARRAY_SIZE(args))));
1356 }
1357 continue;
1358 }
1359 // Do not change DONT_DELETE to false from true.
1349 attr |= lookup.GetAttributes() & DONT_DELETE; 1360 attr |= lookup.GetAttributes() & DONT_DELETE;
1350 } 1361 }
1351 PropertyAttributes attributes = static_cast<PropertyAttributes>(attr); 1362 PropertyAttributes attributes = static_cast<PropertyAttributes>(attr);
1352 1363
1353 RETURN_IF_EMPTY_HANDLE( 1364 RETURN_IF_EMPTY_HANDLE(
1354 isolate, 1365 isolate,
1355 JSObject::SetLocalPropertyIgnoreAttributes(global, name, value, 1366 JSObject::SetLocalPropertyIgnoreAttributes(global, name, value,
1356 attributes)); 1367 attributes));
1357 } else { 1368 } else {
1358 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
1359 StrictModeFlag strict_mode_flag = (language_mode == CLASSIC_MODE)
1360 ? kNonStrictMode : kStrictMode;
1361 RETURN_IF_EMPTY_HANDLE( 1369 RETURN_IF_EMPTY_HANDLE(
1362 isolate, 1370 isolate,
1363 JSReceiver::SetProperty(global, name, value, 1371 JSReceiver::SetProperty(global, name, value,
1364 static_cast<PropertyAttributes>(attr), 1372 static_cast<PropertyAttributes>(attr),
1365 strict_mode_flag)); 1373 language_mode == CLASSIC_MODE
1374 ? kNonStrictMode : kStrictMode));
1366 } 1375 }
1367 } 1376 }
1368 1377
1369 ASSERT(!isolate->has_pending_exception()); 1378 ASSERT(!isolate->has_pending_exception());
1370 return isolate->heap()->undefined_value(); 1379 return isolate->heap()->undefined_value();
1371 } 1380 }
1372 1381
1373 1382
1374 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { 1383 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) {
1375 HandleScope scope(isolate); 1384 HandleScope scope(isolate);
(...skipping 12269 matching lines...) Expand 10 before | Expand all | Expand 10 after
13645 // Handle last resort GC and make sure to allow future allocations 13654 // Handle last resort GC and make sure to allow future allocations
13646 // to grow the heap without causing GCs (if possible). 13655 // to grow the heap without causing GCs (if possible).
13647 isolate->counters()->gc_last_resort_from_js()->Increment(); 13656 isolate->counters()->gc_last_resort_from_js()->Increment();
13648 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13657 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13649 "Runtime::PerformGC"); 13658 "Runtime::PerformGC");
13650 } 13659 }
13651 } 13660 }
13652 13661
13653 13662
13654 } } // namespace v8::internal 13663 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-115452.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698