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/objects.cc

Issue 2362083002: [modules] Do basic linking. (Closed)
Patch Set: Rename files because the presubmit tool is so fragile. Created 4 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 19562 matching lines...) Expand 10 before | Expand all | Expand 10 after
19573 19573
19574 bool JSReceiver::HasProxyInPrototype(Isolate* isolate) { 19574 bool JSReceiver::HasProxyInPrototype(Isolate* isolate) {
19575 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 19575 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
19576 PrototypeIterator::END_AT_NULL); 19576 PrototypeIterator::END_AT_NULL);
19577 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 19577 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
19578 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 19578 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
19579 } 19579 }
19580 return false; 19580 return false;
19581 } 19581 }
19582 19582
19583 void Module::CreateIndirectExport(Handle<Module> module, Handle<String> name,
19584 Handle<ModuleInfoEntry> entry) {
19585 Isolate* isolate = module->GetIsolate();
19586 Handle<ObjectHashTable> exports(module->exports(), isolate);
19587 DCHECK(exports->Lookup(name)->IsTheHole(isolate));
19588 exports = ObjectHashTable::Put(exports, name, entry);
19589 module->set_exports(*exports);
19590 }
19591
19583 void Module::CreateExport(Handle<Module> module, Handle<FixedArray> names) { 19592 void Module::CreateExport(Handle<Module> module, Handle<FixedArray> names) {
19584 DCHECK_LT(0, names->length()); 19593 DCHECK_LT(0, names->length());
19585 Isolate* isolate = module->GetIsolate(); 19594 Isolate* isolate = module->GetIsolate();
19586 Handle<Cell> cell = 19595 Handle<Cell> cell =
19587 isolate->factory()->NewCell(isolate->factory()->undefined_value()); 19596 isolate->factory()->NewCell(isolate->factory()->undefined_value());
19588 Handle<ObjectHashTable> exports(module->exports(), isolate); 19597 Handle<ObjectHashTable> exports(module->exports(), isolate);
19589 for (int i = 0, n = names->length(); i < n; ++i) { 19598 for (int i = 0, n = names->length(); i < n; ++i) {
19590 Handle<String> name(String::cast(names->get(i)), isolate); 19599 Handle<String> name(String::cast(names->get(i)), isolate);
19591 DCHECK(exports->Lookup(name)->IsTheHole(isolate)); 19600 DCHECK(exports->Lookup(name)->IsTheHole(isolate));
19592 exports = ObjectHashTable::Put(exports, name, cell); 19601 exports = ObjectHashTable::Put(exports, name, cell);
19593 } 19602 }
19594 module->set_exports(*exports); 19603 module->set_exports(*exports);
19595 } 19604 }
19596 19605
19597 void Module::StoreExport(Handle<Module> module, Handle<String> name, 19606 void Module::StoreExport(Handle<Module> module, Handle<String> name,
19598 Handle<Object> value) { 19607 Handle<Object> value) {
19599 Handle<ObjectHashTable> exports(module->exports()); 19608 Handle<Cell> cell(Cell::cast(module->exports()->Lookup(name)));
19600 Handle<Cell> cell(Cell::cast(exports->Lookup(name)));
19601 cell->set_value(*value); 19609 cell->set_value(*value);
19602 } 19610 }
19603 19611
19604 Handle<Object> Module::LoadExport(Handle<Module> module, Handle<String> name) { 19612 Handle<Object> Module::LoadExport(Handle<Module> module, Handle<String> name) {
19605 Isolate* isolate = module->GetIsolate(); 19613 Isolate* isolate = module->GetIsolate();
19606 Handle<ObjectHashTable> exports(module->exports(), isolate); 19614 Handle<Object> object(module->exports()->Lookup(name), isolate);
19607 Handle<Cell> cell(Cell::cast(exports->Lookup(name))); 19615
19608 return handle(cell->value(), isolate); 19616 // TODO(neis): Star exports and namespace imports are not yet implemented.
19617 // Trying to use these features may crash here.
19618 if (!object->IsCell()) UNIMPLEMENTED();
19619
19620 return handle(Handle<Cell>::cast(object)->value(), isolate);
19609 } 19621 }
19610 19622
19611 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, 19623 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name,
19612 int module_request) { 19624 int module_request) {
19613 Isolate* isolate = module->GetIsolate(); 19625 Isolate* isolate = module->GetIsolate();
19614 Handle<Module> requested_module( 19626 Handle<Module> requested_module(
19615 Module::cast(module->requested_modules()->get(module_request)), isolate); 19627 Module::cast(module->requested_modules()->get(module_request)), isolate);
19616 Handle<ObjectHashTable> exports(requested_module->exports(), isolate); 19628 return Module::LoadExport(requested_module, name);
19617 Object* object = exports->Lookup(name); 19629 }
19618 if (!object->IsCell()) UNIMPLEMENTED(); 19630
19619 return handle(Cell::cast(object)->value(), isolate); 19631 MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module,
19632 Handle<String> name,
19633 int module_request) {
19634 Isolate* isolate = module->GetIsolate();
19635 Handle<Module> requested_module(
19636 Module::cast(module->requested_modules()->get(module_request)), isolate);
19637 return Module::ResolveExport(requested_module, name);
19638 }
19639
19640 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module,
19641 Handle<String> name) {
19642 // TODO(neis): Detect cycles.
19643
19644 Isolate* isolate = module->GetIsolate();
19645 Handle<Object> object(module->exports()->Lookup(name), isolate);
19646
19647 if (object->IsCell()) {
19648 // Already resolved (e.g. because it's a local export).
19649 return Handle<Cell>::cast(object);
19650 }
19651
19652 if (object->IsModuleInfoEntry()) {
19653 // Not yet resolved indirect export.
19654 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object);
19655 int module_request = Smi::cast(entry->module_request())->value();
19656 Handle<String> import_name(String::cast(entry->import_name()), isolate);
19657
19658 Handle<Cell> cell;
19659 if (!ResolveImport(module, import_name, module_request).ToHandle(&cell)) {
19660 return MaybeHandle<Cell>();
19661 }
19662
19663 // The export table may have changed but the entry in question should be
19664 // unchanged.
19665 Handle<ObjectHashTable> exports(module->exports(), isolate);
19666 DCHECK(exports->Lookup(name)->IsModuleInfoEntry());
19667
19668 exports = ObjectHashTable::Put(exports, name, cell);
19669 module->set_exports(*exports);
19670 return cell;
19671 }
19672
19673 DCHECK(object->IsTheHole(isolate));
19674 // TODO(neis): Implement star exports.
19675
19676 // Unresolvable.
19677 THROW_NEW_ERROR(isolate,
19678 NewSyntaxError(MessageTemplate::kUnresolvableExport, name),
19679 Cell);
19620 } 19680 }
19621 19681
19622 } // namespace internal 19682 } // namespace internal
19623 } // namespace v8 19683 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698