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

Side by Side Diff: src/runtime.cc

Issue 220473014: Make stray 'return' an early error (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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/preparser.cc ('k') | test/cctest/test-parsing.cc » ('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 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 JSObject::DefineAccessor(object, 2110 JSObject::DefineAccessor(object,
2111 name, 2111 name,
2112 InstantiateAccessorComponent(isolate, getter), 2112 InstantiateAccessorComponent(isolate, getter),
2113 InstantiateAccessorComponent(isolate, setter), 2113 InstantiateAccessorComponent(isolate, setter),
2114 static_cast<PropertyAttributes>(attribute), 2114 static_cast<PropertyAttributes>(attribute),
2115 static_cast<v8::AccessControl>(access_control)); 2115 static_cast<v8::AccessControl>(access_control));
2116 return isolate->heap()->undefined_value(); 2116 return isolate->heap()->undefined_value();
2117 } 2117 }
2118 2118
2119 2119
2120 static Failure* ThrowRedeclarationError(Isolate* isolate, 2120 static Failure* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) {
2121 const char* type,
2122 Handle<String> name) {
2123 HandleScope scope(isolate); 2121 HandleScope scope(isolate);
2124 Handle<Object> type_handle = 2122 Handle<Object> args[1] = { name };
2125 isolate->factory()->NewStringFromAscii(CStrVector(type)); 2123 Handle<Object> error = isolate->factory()->NewTypeError(
2126 Handle<Object> args[2] = { type_handle, name }; 2124 "var_redeclaration", HandleVector(args, 1));
2127 Handle<Object> error =
2128 isolate->factory()->NewTypeError("redeclaration", HandleVector(args, 2));
2129 return isolate->Throw(*error); 2125 return isolate->Throw(*error);
2130 } 2126 }
2131 2127
2132 2128
2133 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_DeclareGlobals) { 2129 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_DeclareGlobals) {
2134 HandleScope scope(isolate); 2130 HandleScope scope(isolate);
2135 ASSERT(args.length() == 3); 2131 ASSERT(args.length() == 3);
2136 Handle<GlobalObject> global = Handle<GlobalObject>( 2132 Handle<GlobalObject> global = Handle<GlobalObject>(
2137 isolate->context()->global_object()); 2133 isolate->context()->global_object());
2138 2134
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 } 2191 }
2196 2192
2197 StrictMode strict_mode = DeclareGlobalsStrictMode::decode(flags); 2193 StrictMode strict_mode = DeclareGlobalsStrictMode::decode(flags);
2198 2194
2199 if (!lookup.IsFound() || is_function) { 2195 if (!lookup.IsFound() || is_function) {
2200 // If the local property exists, check that we can reconfigure it 2196 // If the local property exists, check that we can reconfigure it
2201 // as required for function declarations. 2197 // as required for function declarations.
2202 if (lookup.IsFound() && lookup.IsDontDelete()) { 2198 if (lookup.IsFound() && lookup.IsDontDelete()) {
2203 if (lookup.IsReadOnly() || lookup.IsDontEnum() || 2199 if (lookup.IsReadOnly() || lookup.IsDontEnum() ||
2204 lookup.IsPropertyCallbacks()) { 2200 lookup.IsPropertyCallbacks()) {
2205 return ThrowRedeclarationError(isolate, "function", name); 2201 return ThrowRedeclarationError(isolate, name);
marja 2014/04/02 12:29:57 Why don't we differentiate between "function", "co
rossberg 2014/04/02 12:34:43 Because it wasn't very meaningful. When you had
2206 } 2202 }
2207 // If the existing property is not configurable, keep its attributes. 2203 // If the existing property is not configurable, keep its attributes.
2208 attr = lookup.GetAttributes(); 2204 attr = lookup.GetAttributes();
2209 } 2205 }
2210 // Define or redefine own property. 2206 // Define or redefine own property.
2211 RETURN_IF_EMPTY_HANDLE(isolate, 2207 RETURN_IF_EMPTY_HANDLE(isolate,
2212 JSObject::SetLocalPropertyIgnoreAttributes( 2208 JSObject::SetLocalPropertyIgnoreAttributes(
2213 global, name, value, static_cast<PropertyAttributes>(attr))); 2209 global, name, value, static_cast<PropertyAttributes>(attr)));
2214 } else { 2210 } else {
2215 // Do a [[Put]] on the existing (own) property. 2211 // Do a [[Put]] on the existing (own) property.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 Handle<Object> holder = 2243 Handle<Object> holder =
2248 context->Lookup(name, flags, &index, &attributes, &binding_flags); 2244 context->Lookup(name, flags, &index, &attributes, &binding_flags);
2249 2245
2250 if (attributes != ABSENT) { 2246 if (attributes != ABSENT) {
2251 // The name was declared before; check for conflicting re-declarations. 2247 // The name was declared before; check for conflicting re-declarations.
2252 // Note: this is actually inconsistent with what happens for globals (where 2248 // Note: this is actually inconsistent with what happens for globals (where
2253 // we silently ignore such declarations). 2249 // we silently ignore such declarations).
2254 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) { 2250 if (((attributes & READ_ONLY) != 0) || (mode == READ_ONLY)) {
2255 // Functions are not read-only. 2251 // Functions are not read-only.
2256 ASSERT(mode != READ_ONLY || initial_value->IsTheHole()); 2252 ASSERT(mode != READ_ONLY || initial_value->IsTheHole());
2257 const char* type = ((attributes & READ_ONLY) != 0) ? "const" : "var"; 2253 return ThrowRedeclarationError(isolate, name);
2258 return ThrowRedeclarationError(isolate, type, name);
2259 } 2254 }
2260 2255
2261 // Initialize it if necessary. 2256 // Initialize it if necessary.
2262 if (*initial_value != NULL) { 2257 if (*initial_value != NULL) {
2263 if (index >= 0) { 2258 if (index >= 0) {
2264 ASSERT(holder.is_identical_to(context)); 2259 ASSERT(holder.is_identical_to(context));
2265 if (((attributes & READ_ONLY) == 0) || 2260 if (((attributes & READ_ONLY) == 0) ||
2266 context->get(index)->IsTheHole()) { 2261 context->get(index)->IsTheHole()) {
2267 context->set(index, *initial_value); 2262 context->set(index, *initial_value);
2268 } 2263 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 // there is a callback with that name in a prototype. It is 2297 // there is a callback with that name in a prototype. It is
2303 // allowed to introduce const variables in 2298 // allowed to introduce const variables in
2304 // JSContextExtensionObjects. They are treated specially in 2299 // JSContextExtensionObjects. They are treated specially in
2305 // SetProperty and no setters are invoked for those since they are 2300 // SetProperty and no setters are invoked for those since they are
2306 // not real JSObjects. 2301 // not real JSObjects.
2307 if (initial_value->IsTheHole() && 2302 if (initial_value->IsTheHole() &&
2308 !object->IsJSContextExtensionObject()) { 2303 !object->IsJSContextExtensionObject()) {
2309 LookupResult lookup(isolate); 2304 LookupResult lookup(isolate);
2310 object->Lookup(*name, &lookup); 2305 object->Lookup(*name, &lookup);
2311 if (lookup.IsPropertyCallbacks()) { 2306 if (lookup.IsPropertyCallbacks()) {
2312 return ThrowRedeclarationError(isolate, "const", name); 2307 return ThrowRedeclarationError(isolate, name);
2313 } 2308 }
2314 } 2309 }
2315 if (object->IsJSGlobalObject()) { 2310 if (object->IsJSGlobalObject()) {
2316 // Define own property on the global object. 2311 // Define own property on the global object.
2317 RETURN_IF_EMPTY_HANDLE(isolate, 2312 RETURN_IF_EMPTY_HANDLE(isolate,
2318 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode)); 2313 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode));
2319 } else { 2314 } else {
2320 RETURN_IF_EMPTY_HANDLE(isolate, 2315 RETURN_IF_EMPTY_HANDLE(isolate,
2321 JSReceiver::SetProperty(object, name, value, mode, SLOPPY)); 2316 JSReceiver::SetProperty(object, name, value, mode, SLOPPY));
2322 } 2317 }
(...skipping 12908 matching lines...) Expand 10 before | Expand all | Expand 10 after
15231 } 15226 }
15232 } 15227 }
15233 15228
15234 15229
15235 void Runtime::OutOfMemory() { 15230 void Runtime::OutOfMemory() {
15236 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); 15231 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);
15237 UNREACHABLE(); 15232 UNREACHABLE();
15238 } 15233 }
15239 15234
15240 } } // namespace v8::internal 15235 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698