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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-115452.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 019851e466a363948a3338c171eeac531b0290c4..195dc8808ec1c853499f1cac52bdd3492181d910 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -1336,6 +1336,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
attr |= READ_ONLY;
}
+ LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
+
// Safari does not allow the invocation of callback setters for
// function declarations. To mimic this behavior, we do not allow
// the invocation of setters for function values. This makes a
@@ -1343,9 +1345,18 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
// handlers such as "function onload() {}". Firefox does call the
// onload setter in those case and Safari does not. We follow
// Safari for compatibility.
- if (value->IsJSFunction()) {
- // Do not change DONT_DELETE to false from true.
+ if (is_function_declaration) {
if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) {
+ // Do not overwrite READ_ONLY properties.
+ if (lookup.GetAttributes() & READ_ONLY) {
+ if (language_mode != CLASSIC_MODE) {
+ Handle<Object> args[] = { name };
+ return isolate->Throw(*isolate->factory()->NewTypeError(
+ "strict_cannot_assign", HandleVector(args, ARRAY_SIZE(args))));
+ }
+ continue;
+ }
+ // Do not change DONT_DELETE to false from true.
attr |= lookup.GetAttributes() & DONT_DELETE;
}
PropertyAttributes attributes = static_cast<PropertyAttributes>(attr);
@@ -1355,14 +1366,12 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
JSObject::SetLocalPropertyIgnoreAttributes(global, name, value,
attributes));
} else {
- LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
- StrictModeFlag strict_mode_flag = (language_mode == CLASSIC_MODE)
- ? kNonStrictMode : kStrictMode;
RETURN_IF_EMPTY_HANDLE(
isolate,
JSReceiver::SetProperty(global, name, value,
static_cast<PropertyAttributes>(attr),
- strict_mode_flag));
+ language_mode == CLASSIC_MODE
+ ? kNonStrictMode : kStrictMode));
}
}
« 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