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

Side by Side Diff: src/runtime.cc

Issue 11093074: Get rid of static module allocation, do it in code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed last comments; added other back-ends Created 8 years, 1 month 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/scopeinfo.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 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 HandleScope scope(isolate); 1351 HandleScope scope(isolate);
1352 Handle<String> name(String::cast(pairs->get(i))); 1352 Handle<String> name(String::cast(pairs->get(i)));
1353 Handle<Object> value(pairs->get(i + 1), isolate); 1353 Handle<Object> value(pairs->get(i + 1), isolate);
1354 1354
1355 // We have to declare a global const property. To capture we only 1355 // We have to declare a global const property. To capture we only
1356 // assign to it when evaluating the assignment for "const x = 1356 // assign to it when evaluating the assignment for "const x =
1357 // <expr>" the initial value is the hole. 1357 // <expr>" the initial value is the hole.
1358 bool is_var = value->IsUndefined(); 1358 bool is_var = value->IsUndefined();
1359 bool is_const = value->IsTheHole(); 1359 bool is_const = value->IsTheHole();
1360 bool is_function = value->IsSharedFunctionInfo(); 1360 bool is_function = value->IsSharedFunctionInfo();
1361 bool is_module = value->IsJSModule(); 1361 ASSERT(is_var + is_const + is_function == 1);
1362 ASSERT(is_var + is_const + is_function + is_module == 1);
1363 1362
1364 if (is_var || is_const) { 1363 if (is_var || is_const) {
1365 // Lookup the property in the global object, and don't set the 1364 // Lookup the property in the global object, and don't set the
1366 // value of the variable if the property is already there. 1365 // value of the variable if the property is already there.
1367 // Do the lookup locally only, see ES5 erratum. 1366 // Do the lookup locally only, see ES5 erratum.
1368 LookupResult lookup(isolate); 1367 LookupResult lookup(isolate);
1369 if (FLAG_es52_globals) { 1368 if (FLAG_es52_globals) {
1370 Object* obj = *global; 1369 Object* obj = *global;
1371 do { 1370 do {
1372 JSObject::cast(obj)->LocalLookup(*name, &lookup); 1371 JSObject::cast(obj)->LocalLookup(*name, &lookup);
(...skipping 23 matching lines...) Expand all
1396 value = function; 1395 value = function;
1397 } 1396 }
1398 1397
1399 LookupResult lookup(isolate); 1398 LookupResult lookup(isolate);
1400 global->LocalLookup(*name, &lookup); 1399 global->LocalLookup(*name, &lookup);
1401 1400
1402 // Compute the property attributes. According to ECMA-262, 1401 // Compute the property attributes. According to ECMA-262,
1403 // the property must be non-configurable except in eval. 1402 // the property must be non-configurable except in eval.
1404 int attr = NONE; 1403 int attr = NONE;
1405 bool is_eval = DeclareGlobalsEvalFlag::decode(flags); 1404 bool is_eval = DeclareGlobalsEvalFlag::decode(flags);
1406 if (!is_eval || is_module) { 1405 if (!is_eval) {
1407 attr |= DONT_DELETE; 1406 attr |= DONT_DELETE;
1408 } 1407 }
1409 bool is_native = DeclareGlobalsNativeFlag::decode(flags); 1408 bool is_native = DeclareGlobalsNativeFlag::decode(flags);
1410 if (is_const || is_module || (is_native && is_function)) { 1409 if (is_const || (is_native && is_function)) {
1411 attr |= READ_ONLY; 1410 attr |= READ_ONLY;
1412 } 1411 }
1413 1412
1414 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags); 1413 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags);
1415 1414
1416 if (!lookup.IsFound() || is_function || is_module) { 1415 if (!lookup.IsFound() || is_function) {
1417 // If the local property exists, check that we can reconfigure it 1416 // If the local property exists, check that we can reconfigure it
1418 // as required for function declarations. 1417 // as required for function declarations.
1419 if (lookup.IsFound() && lookup.IsDontDelete()) { 1418 if (lookup.IsFound() && lookup.IsDontDelete()) {
1420 if (lookup.IsReadOnly() || lookup.IsDontEnum() || 1419 if (lookup.IsReadOnly() || lookup.IsDontEnum() ||
1421 lookup.IsPropertyCallbacks()) { 1420 lookup.IsPropertyCallbacks()) {
1422 return ThrowRedeclarationError( 1421 return ThrowRedeclarationError(isolate, "function", name);
1423 isolate, is_function ? "function" : "module", name);
1424 } 1422 }
1425 // If the existing property is not configurable, keep its attributes. 1423 // If the existing property is not configurable, keep its attributes.
1426 attr = lookup.GetAttributes(); 1424 attr = lookup.GetAttributes();
1427 } 1425 }
1428 // Define or redefine own property. 1426 // Define or redefine own property.
1429 RETURN_IF_EMPTY_HANDLE(isolate, 1427 RETURN_IF_EMPTY_HANDLE(isolate,
1430 JSObject::SetLocalPropertyIgnoreAttributes( 1428 JSObject::SetLocalPropertyIgnoreAttributes(
1431 global, name, value, static_cast<PropertyAttributes>(attr))); 1429 global, name, value, static_cast<PropertyAttributes>(attr)));
1432 } else { 1430 } else {
1433 // Do a [[Put]] on the existing (own) property. 1431 // Do a [[Put]] on the existing (own) property.
(...skipping 7037 matching lines...) Expand 10 before | Expand all | Expand 10 after
8471 8469
8472 8470
8473 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSModule) { 8471 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSModule) {
8474 ASSERT(args.length() == 1); 8472 ASSERT(args.length() == 1);
8475 Object* obj = args[0]; 8473 Object* obj = args[0];
8476 return isolate->heap()->ToBoolean(obj->IsJSModule()); 8474 return isolate->heap()->ToBoolean(obj->IsJSModule());
8477 } 8475 }
8478 8476
8479 8477
8480 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushModuleContext) { 8478 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushModuleContext) {
8481 NoHandleAllocation ha; 8479 ASSERT(args.length() == 2);
8482 ASSERT(args.length() == 1); 8480 CONVERT_SMI_ARG_CHECKED(index, 0);
8483 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 0);
8484 8481
8485 Context* context = Context::cast(instance->context()); 8482 if (!args[1]->IsScopeInfo()) {
8483 // Module already initialized. Find hosting context and retrieve context.
8484 Context* host = Context::cast(isolate->context())->global_context();
8485 Context* context = Context::cast(host->get(index));
8486 ASSERT(context->previous() == isolate->context());
8487 isolate->set_context(context);
8488 return context;
8489 }
8490
8491 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
8492
8493 // Allocate module context.
8494 HandleScope scope(isolate);
8495 Factory* factory = isolate->factory();
8496 Handle<Context> context = factory->NewModuleContext(scope_info);
8497 Handle<JSModule> module = factory->NewJSModule(context, scope_info);
8498 context->set_module(*module);
8486 Context* previous = isolate->context(); 8499 Context* previous = isolate->context();
8487 ASSERT(context->IsModuleContext());
8488 // Initialize the context links.
8489 context->set_previous(previous); 8500 context->set_previous(previous);
8490 context->set_closure(previous->closure()); 8501 context->set_closure(previous->closure());
8491 context->set_global_object(previous->global_object()); 8502 context->set_global_object(previous->global_object());
8492 isolate->set_context(context); 8503 isolate->set_context(*context);
8493 8504
8494 return context; 8505 // Find hosting scope and initialize internal variable holding module there.
8506 previous->global_context()->set(index, *context);
8507
8508 return *context;
8495 } 8509 }
8496 8510
8497 8511
8512 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareModules) {
8513 HandleScope scope(isolate);
8514 ASSERT(args.length() == 1);
8515 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0);
8516 Context* host_context = isolate->context();
8517
8518 for (int i = 0; i < descriptions->length(); ++i) {
8519 Handle<ModuleInfo> description(ModuleInfo::cast(descriptions->get(i)));
8520 int host_index = description->host_index();
8521 Handle<Context> context(Context::cast(host_context->get(host_index)));
8522 Handle<JSModule> module(context->module());
8523
8524 for (int j = 0; j < description->length(); ++j) {
8525 Handle<String> name(description->name(j));
8526 VariableMode mode = description->mode(j);
8527 int index = description->index(j);
8528 switch (mode) {
8529 case VAR:
8530 case LET:
8531 case CONST:
8532 case CONST_HARMONY: {
8533 PropertyAttributes attr =
8534 IsImmutableVariableMode(mode) ? FROZEN : SEALED;
8535 Handle<AccessorInfo> info =
8536 Accessors::MakeModuleExport(name, index, attr);
8537 Handle<Object> result = SetAccessor(module, info);
8538 ASSERT(!(result.is_null() || result->IsUndefined()));
8539 USE(result);
8540 break;
8541 }
8542 case MODULE: {
8543 Object* referenced_context = Context::cast(host_context)->get(index);
8544 Handle<JSModule> value(Context::cast(referenced_context)->module());
8545 JSReceiver::SetProperty(module, name, value, FROZEN, kStrictMode);
8546 break;
8547 }
8548 case INTERNAL:
8549 case TEMPORARY:
8550 case DYNAMIC:
8551 case DYNAMIC_GLOBAL:
8552 case DYNAMIC_LOCAL:
8553 UNREACHABLE();
8554 }
8555 }
8556
8557 JSObject::PreventExtensions(module);
8558 }
8559
8560 ASSERT(!isolate->has_pending_exception());
8561 return isolate->heap()->undefined_value();
8562 }
8563
8564
8498 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { 8565 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) {
8499 HandleScope scope(isolate); 8566 HandleScope scope(isolate);
8500 ASSERT(args.length() == 2); 8567 ASSERT(args.length() == 2);
8501 8568
8502 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0); 8569 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0);
8503 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); 8570 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
8504 8571
8505 int index; 8572 int index;
8506 PropertyAttributes attributes; 8573 PropertyAttributes attributes;
8507 ContextLookupFlags flags = FOLLOW_CHAINS; 8574 ContextLookupFlags flags = FOLLOW_CHAINS;
(...skipping 4771 matching lines...) Expand 10 before | Expand all | Expand 10 after
13279 // Handle last resort GC and make sure to allow future allocations 13346 // Handle last resort GC and make sure to allow future allocations
13280 // to grow the heap without causing GCs (if possible). 13347 // to grow the heap without causing GCs (if possible).
13281 isolate->counters()->gc_last_resort_from_js()->Increment(); 13348 isolate->counters()->gc_last_resort_from_js()->Increment();
13282 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13349 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13283 "Runtime::PerformGC"); 13350 "Runtime::PerformGC");
13284 } 13351 }
13285 } 13352 }
13286 13353
13287 13354
13288 } } // namespace v8::internal 13355 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/scopeinfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698