Chromium Code Reviews| Index: src/accessors.cc |
| diff --git a/src/accessors.cc b/src/accessors.cc |
| index 8048738b28e487b40971a7e302176a6248c7395c..72bcc75b67b93ce1ac08627052a120347f65e6d0 100644 |
| --- a/src/accessors.cc |
| +++ b/src/accessors.cc |
| @@ -802,4 +802,69 @@ const AccessorDescriptor Accessors::ObjectPrototype = { |
| 0 |
| }; |
| + |
| +// |
| +// Accessors::MakeModuleExport |
| +// |
| + |
| +static v8::Handle<v8::Value> ModuleGetExport( |
| + v8::Local<v8::String> property, |
| + const v8::AccessorInfo& info) { |
| + JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
| + Context* context = Context::cast(instance->context()); |
| + ASSERT(context->IsModuleContext()); |
| + int slot = info.Data()->Int32Value(); |
| + Object* value = context->get(slot); |
| + if (value->IsTheHole()) { |
| + Handle<String> name = v8::Utils::OpenHandle(*property); |
| + Isolate* isolate = instance->GetIsolate(); |
| + isolate->ScheduleThrow( |
| + *isolate->factory()->NewReferenceError("not_defined", |
| + HandleVector(&name, 1))); |
| + return v8::Handle<v8::Value>(); |
| + } |
| + return v8::Utils::ToLocal(Handle<Object>(value)); |
| +} |
| + |
| + |
| +static void ModuleSetExport( |
| + v8::Local<v8::String> property, |
| + v8::Local<v8::Value> value, |
| + const v8::AccessorInfo& info) { |
| + JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
| + Context* context = Context::cast(instance->context()); |
| + ASSERT(context->IsModuleContext()); |
| + int slot = info.Data()->Int32Value(); |
| + Object* old_value = context->get(slot); |
| + if (old_value->IsTheHole()) { |
| + Handle<String> name = v8::Utils::OpenHandle(*property); |
| + Isolate* isolate = instance->GetIsolate(); |
| + isolate->ScheduleThrow( |
| + *isolate->factory()->NewReferenceError("not_defined", |
| + HandleVector(&name, 1))); |
| + return; |
| + } |
| + context->set(slot, *v8::Utils::OpenHandle(*value)); |
| +} |
| + |
| + |
| +Handle<AccessorInfo> Accessors::MakeModuleExport( |
| + Handle<String> name, |
| + int index, |
| + PropertyAttributes attributes) { |
| + Factory* factory = Isolate::Current()->factory(); |
|
Michael Starzinger
2012/07/06 10:53:22
Use name->GetIsolate() instead.
rossberg
2012/07/06 15:39:28
Done.
|
| + Handle<AccessorInfo> info = factory->NewAccessorInfo(); |
| + info->set_property_attributes(attributes); |
| + info->set_all_can_read(true); |
| + info->set_all_can_write(true); |
| + info->set_name(*name); |
| + info->set_data(Smi::FromInt(index)); |
| + v8::AccessorGetter getter = &ModuleGetExport; |
| + v8::AccessorSetter setter = &ModuleSetExport; |
| + info->set_getter(*v8::FromCData(getter)); |
| + if (!(attributes & ReadOnly)) info->set_setter(*v8::FromCData(setter)); |
| + return info; |
| +} |
| + |
| + |
| } } // namespace v8::internal |