OLD | NEW |
---|---|
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 Loading... | |
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<ObjectHashTable> exports(module->exports()); |
19600 Handle<Cell> cell(Cell::cast(exports->Lookup(name))); | 19609 Handle<Cell> cell(Cell::cast(exports->Lookup(name))); |
19601 cell->set_value(*value); | 19610 cell->set_value(*value); |
19602 } | 19611 } |
19603 | 19612 |
19604 Handle<Object> Module::LoadExport(Handle<Module> module, Handle<String> name) { | 19613 Handle<Object> Module::LoadExport(Handle<Module> module, Handle<String> name) { |
19605 Isolate* isolate = module->GetIsolate(); | 19614 Isolate* isolate = module->GetIsolate(); |
19606 Handle<ObjectHashTable> exports(module->exports(), isolate); | 19615 Handle<ObjectHashTable> exports(module->exports(), isolate); |
19607 Handle<Cell> cell(Cell::cast(exports->Lookup(name))); | 19616 Object* object = exports->Lookup(name); |
adamk
2016/09/23 00:51:40
Please put this in a handle for consistency.
neis
2016/09/23 17:40:33
Done.
| |
19608 return handle(cell->value(), isolate); | 19617 if (!object->IsCell()) UNIMPLEMENTED(); |
adamk
2016/09/23 00:51:40
Can you add a comment here explaining what needs t
neis
2016/09/23 17:40:33
Done.
| |
19618 return handle(Cell::cast(object)->value(), isolate); | |
19609 } | 19619 } |
19610 | 19620 |
19611 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, | 19621 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, |
19612 int module_request) { | 19622 int module_request) { |
19613 Isolate* isolate = module->GetIsolate(); | 19623 Isolate* isolate = module->GetIsolate(); |
19614 Handle<Module> requested_module( | 19624 Handle<Module> requested_module( |
19615 Module::cast(module->requested_modules()->get(module_request)), isolate); | 19625 Module::cast(module->requested_modules()->get(module_request)), isolate); |
19616 Handle<ObjectHashTable> exports(requested_module->exports(), isolate); | 19626 return Module::LoadExport(requested_module, name); |
19617 Object* object = exports->Lookup(name); | 19627 } |
19618 if (!object->IsCell()) UNIMPLEMENTED(); | 19628 |
19619 return handle(Cell::cast(object)->value(), isolate); | 19629 MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, |
19630 Handle<String> name, | |
19631 int module_request) { | |
19632 Isolate* isolate = module->GetIsolate(); | |
19633 Handle<Module> requested_module( | |
19634 Module::cast(module->requested_modules()->get(module_request)), isolate); | |
19635 return Module::ResolveExport(requested_module, name); | |
19636 } | |
19637 | |
19638 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, | |
19639 Handle<String> name) { | |
19640 // TODO(neis): Support recursion. | |
19641 | |
19642 Isolate* isolate = module->GetIsolate(); | |
19643 Handle<Object> object(module->exports()->Lookup(name), isolate); | |
19644 | |
19645 if (object->IsCell()) { | |
19646 // Already resolved (e.g. because it's a local export). | |
19647 return Handle<Cell>::cast(object); | |
19648 } | |
19649 | |
19650 if (object->IsModuleInfoEntry()) { | |
19651 // Not yet resolved indirect export. | |
19652 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); | |
19653 int module_request = Smi::cast(entry->module_request())->value(); | |
19654 Handle<String> import_name(String::cast(entry->import_name()), isolate); | |
19655 | |
19656 Handle<Cell> cell; | |
19657 if (!ResolveImport(module, import_name, module_request).ToHandle(&cell)) { | |
19658 return MaybeHandle<Cell>(); | |
19659 } | |
19660 | |
19661 // The export table may have changed but the entry in question should be | |
19662 // unchanged. | |
19663 Handle<ObjectHashTable> exports(module->exports(), isolate); | |
19664 DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); | |
19665 | |
19666 exports = ObjectHashTable::Put(exports, name, cell); | |
19667 module->set_exports(*exports); | |
19668 return cell; | |
19669 } | |
19670 | |
19671 DCHECK(object->IsTheHole(isolate)); | |
19672 // TODO(neis): Implement star exports. | |
19673 | |
19674 // Unresolvable. | |
19675 THROW_NEW_ERROR(isolate, | |
19676 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), | |
19677 Cell); | |
19620 } | 19678 } |
19621 | 19679 |
19622 } // namespace internal | 19680 } // namespace internal |
19623 } // namespace v8 | 19681 } // namespace v8 |
OLD | NEW |