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

Side by Side Diff: src/runtime.cc

Issue 9704054: Refactoring of code generation for declarations, in preparation for modules. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Florian's comments. 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/parser.cc ('k') | src/scopeinfo.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 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->IsJSObject();
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.
1297 LookupResult lookup(isolate); 1301 LookupResult lookup(isolate);
1298 global->Lookup(*name, &lookup); 1302 global->Lookup(*name, &lookup);
1299 if (lookup.IsProperty()) { 1303 if (lookup.IsProperty()) {
1300 // We found an existing property. Unless it was an interceptor 1304 // We found an existing property. Unless it was an interceptor
1301 // that claims the property is absent, skip this declaration. 1305 // that claims the property is absent, skip this declaration.
1302 if (lookup.type() != INTERCEPTOR) { 1306 if (lookup.type() != INTERCEPTOR) continue;
1303 continue;
1304 }
1305 PropertyAttributes attributes = global->GetPropertyAttribute(*name); 1307 PropertyAttributes attributes = global->GetPropertyAttribute(*name);
1306 if (attributes != ABSENT) { 1308 if (attributes != ABSENT) continue;
1307 continue;
1308 }
1309 // Fall-through and introduce the absent property by using 1309 // Fall-through and introduce the absent property by using
1310 // SetProperty. 1310 // SetProperty.
1311 } 1311 }
1312 } else { 1312 } else if (is_function) {
1313 is_function_declaration = true;
1314 // Copy the function and update its context. Use it as value. 1313 // Copy the function and update its context. Use it as value.
1315 Handle<SharedFunctionInfo> shared = 1314 Handle<SharedFunctionInfo> shared =
1316 Handle<SharedFunctionInfo>::cast(value); 1315 Handle<SharedFunctionInfo>::cast(value);
1317 Handle<JSFunction> function = 1316 Handle<JSFunction> function =
1318 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 1317 isolate->factory()->NewFunctionFromSharedFunctionInfo(
1319 context, 1318 shared, context, TENURED);
1320 TENURED);
1321 value = function; 1319 value = function;
1322 } 1320 }
1323 1321
1324 LookupResult lookup(isolate); 1322 LookupResult lookup(isolate);
1325 global->LocalLookup(*name, &lookup); 1323 global->LocalLookup(*name, &lookup);
1326 1324
1327 // Compute the property attributes. According to ECMA-262, section 1325 // Compute the property attributes. According to ECMA-262,
1328 // 13, page 71, the property must be read-only and 1326 // 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; 1327 int attr = NONE;
1332 if (!DeclareGlobalsEvalFlag::decode(flags)) { 1328 bool is_eval = DeclareGlobalsEvalFlag::decode(flags);
1329 if (!is_eval || is_module) {
1333 attr |= DONT_DELETE; 1330 attr |= DONT_DELETE;
1334 } 1331 }
1335 bool is_native = DeclareGlobalsNativeFlag::decode(flags); 1332 bool is_native = DeclareGlobalsNativeFlag::decode(flags);
1336 if (is_const_property || (is_native && is_function_declaration)) { 1333 if (is_const || is_module || (is_native && is_function)) {
1337 attr |= READ_ONLY; 1334 attr |= READ_ONLY;
1338 } 1335 }
1339 1336
1340 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags); 1337 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
1341 1338
1342 // Safari does not allow the invocation of callback setters for 1339 // Safari does not allow the invocation of callback setters for
1343 // function declarations. To mimic this behavior, we do not allow 1340 // function declarations. To mimic this behavior, we do not allow
1344 // the invocation of setters for function values. This makes a 1341 // the invocation of setters for function values. This makes a
1345 // difference for global functions with the same names as event 1342 // difference for global functions with the same names as event
1346 // handlers such as "function onload() {}". Firefox does call the 1343 // handlers such as "function onload() {}". Firefox does call the
1347 // onload setter in those case and Safari does not. We follow 1344 // onload setter in those case and Safari does not. We follow
1348 // Safari for compatibility. 1345 // Safari for compatibility.
1349 if (is_function_declaration) { 1346 if (is_function || is_module) {
1350 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) { 1347 if (lookup.IsProperty() && (lookup.type() != INTERCEPTOR)) {
1351 // Do not overwrite READ_ONLY properties. 1348 // Do not overwrite READ_ONLY properties.
1352 if (lookup.GetAttributes() & READ_ONLY) { 1349 if (lookup.GetAttributes() & READ_ONLY) {
1353 if (language_mode != CLASSIC_MODE) { 1350 if (language_mode != CLASSIC_MODE) {
1354 Handle<Object> args[] = { name }; 1351 Handle<Object> args[] = { name };
1355 return isolate->Throw(*isolate->factory()->NewTypeError( 1352 return isolate->Throw(*isolate->factory()->NewTypeError(
1356 "strict_cannot_assign", HandleVector(args, ARRAY_SIZE(args)))); 1353 "strict_cannot_assign", HandleVector(args, ARRAY_SIZE(args))));
1357 } 1354 }
1358 continue; 1355 continue;
1359 } 1356 }
(...skipping 11982 matching lines...) Expand 10 before | Expand all | Expand 10 after
13342 // Handle last resort GC and make sure to allow future allocations 13339 // Handle last resort GC and make sure to allow future allocations
13343 // to grow the heap without causing GCs (if possible). 13340 // to grow the heap without causing GCs (if possible).
13344 isolate->counters()->gc_last_resort_from_js()->Increment(); 13341 isolate->counters()->gc_last_resort_from_js()->Increment();
13345 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13342 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13346 "Runtime::PerformGC"); 13343 "Runtime::PerformGC");
13347 } 13344 }
13348 } 13345 }
13349 13346
13350 13347
13351 } } // namespace v8::internal 13348 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698