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

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: Created 8 years, 2 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
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);
Sven Panne 2012/11/20 14:39:13 Cunning check for mutual exclusion... o_O Anyway,
rossberg 2012/11/20 17:23:45 You think so? There actually was a subtle bug with
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());
8485 while (host->IsModuleContext()) host = host->previous();
8486 ASSERT(host->IsGlobalContext());
8487 Context* context = Context::cast(host->get(index));
8488 ASSERT(context->previous() == isolate->context());
8489 isolate->set_context(context);
8490 return context;
8491 }
8492
8493 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
8494
8495 // Allocate module context.
8496 HandleScope scope(isolate);
8497 Factory* factory = isolate->factory();
8498 Handle<Context> context = factory->NewModuleContext(scope_info);
8499 Handle<JSModule> module = factory->NewJSModule(context, scope_info);
8500 context->set_module(*module);
8486 Context* previous = isolate->context(); 8501 Context* previous = isolate->context();
8487 ASSERT(context->IsModuleContext());
8488 // Initialize the context links.
8489 context->set_previous(previous); 8502 context->set_previous(previous);
8490 context->set_closure(previous->closure()); 8503 context->set_closure(previous->closure());
8491 context->set_global_object(previous->global_object()); 8504 context->set_global_object(previous->global_object());
8492 isolate->set_context(context); 8505 isolate->set_context(*context);
8493 8506
8494 return context; 8507 // Find hosting scope and initialize internal variable holding module there.
8508 while (previous->IsModuleContext()) previous = previous->previous();
Michael Starzinger 2012/11/20 12:05:05 Use a Context::global_context() helper here.
rossberg 2012/11/20 17:23:45 Done.
8509 ASSERT(previous->IsGlobalContext());
8510 previous->set(index, *context);
8511
8512 return *context;
8495 } 8513 }
8496 8514
8497 8515
8516 static const PropertyAttributes ro_attr =
8517 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE | DONT_ENUM);
Michael Starzinger 2012/11/20 12:05:05 It might make sense to move these constants into t
Sven Panne 2012/11/20 14:39:13 ... and it would make even more sense to clean up
rossberg 2012/11/20 17:23:45 Done.
rossberg 2012/11/20 17:23:45 Yeah...
8518 static const PropertyAttributes rw_attr =
8519 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM);
8520
8521
8522 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareModules) {
8523 HandleScope scope(isolate);
8524 ASSERT(args.length() == 1);
8525 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0);
8526 Context* host_context = isolate->context();
8527
8528 // See FullCodeGen::LinkModules for the format of descriptions.
8529
8530 for (int i = 0; i < descriptions->length(); ++i) {
8531 Handle<FixedArray> description(FixedArray::cast(descriptions->get(i)));
8532 int host_index = Smi::cast(description->get(0))->value();
8533 Handle<Context> context(Context::cast(host_context->get(host_index)));
8534 Handle<JSModule> module(context->module());
8535
8536 // And populate it.
8537 for (int j = 1; j < description->length(); j += 3) {
8538 Handle<String> name(String::cast(description->get(j)));
8539 VariableMode mode =
8540 static_cast<VariableMode>(Smi::cast(description->get(j + 1))->value());
8541 int index = Smi::cast(description->get(j + 2))->value();
8542 switch (mode) {
8543 case VAR:
8544 case LET:
8545 case CONST:
8546 case CONST_HARMONY: {
8547 PropertyAttributes attr =
8548 IsImmutableVariableMode(mode) ? ro_attr : rw_attr;
8549 Handle<AccessorInfo> info =
8550 Accessors::MakeModuleExport(name, index, attr);
8551 Handle<Object> result = SetAccessor(module, info);
8552 ASSERT(!(result.is_null() || result->IsUndefined()));
8553 USE(result);
8554 break;
8555 }
8556 case MODULE: {
8557 Object* referenced_context = Context::cast(host_context)->get(index);
8558 Handle<JSModule> value(Context::cast(referenced_context)->module());
8559 JSReceiver::SetProperty(module, name, value, ro_attr, kStrictMode);
8560 break;
8561 }
8562 case INTERNAL:
8563 case TEMPORARY:
8564 case DYNAMIC:
8565 case DYNAMIC_GLOBAL:
8566 case DYNAMIC_LOCAL:
8567 UNREACHABLE();
8568 }
8569 }
8570
8571 USE(JSObject::PreventExtensions(module));
Michael Starzinger 2012/11/20 12:05:05 There should be no need to use the return value of
rossberg 2012/11/20 17:23:45 Done.
8572 }
8573
8574 ASSERT(!isolate->has_pending_exception());
8575 return isolate->heap()->undefined_value();
8576 }
8577
8578
8498 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { 8579 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) {
8499 HandleScope scope(isolate); 8580 HandleScope scope(isolate);
8500 ASSERT(args.length() == 2); 8581 ASSERT(args.length() == 2);
8501 8582
8502 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0); 8583 CONVERT_ARG_HANDLE_CHECKED(Context, context, 0);
8503 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); 8584 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
8504 8585
8505 int index; 8586 int index;
8506 PropertyAttributes attributes; 8587 PropertyAttributes attributes;
8507 ContextLookupFlags flags = FOLLOW_CHAINS; 8588 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 13360 // Handle last resort GC and make sure to allow future allocations
13280 // to grow the heap without causing GCs (if possible). 13361 // to grow the heap without causing GCs (if possible).
13281 isolate->counters()->gc_last_resort_from_js()->Increment(); 13362 isolate->counters()->gc_last_resort_from_js()->Increment();
13282 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13363 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13283 "Runtime::PerformGC"); 13364 "Runtime::PerformGC");
13284 } 13365 }
13285 } 13366 }
13286 13367
13287 13368
13288 } } // namespace v8::internal 13369 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698