OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/accessors.h" | 5 #include "src/accessors.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/contexts.h" | 8 #include "src/contexts.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/execution.h" | 10 #include "src/execution.h" |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 info.GetReturnValue().Set(Utils::ToLocal(result)); | 1103 info.GetReturnValue().Set(Utils::ToLocal(result)); |
1104 } | 1104 } |
1105 | 1105 |
1106 Handle<AccessorInfo> Accessors::BoundFunctionNameInfo( | 1106 Handle<AccessorInfo> Accessors::BoundFunctionNameInfo( |
1107 Isolate* isolate, PropertyAttributes attributes) { | 1107 Isolate* isolate, PropertyAttributes attributes) { |
1108 return MakeAccessor(isolate, isolate->factory()->name_string(), | 1108 return MakeAccessor(isolate, isolate->factory()->name_string(), |
1109 &BoundFunctionNameGetter, &ReconfigureToDataProperty, | 1109 &BoundFunctionNameGetter, &ReconfigureToDataProperty, |
1110 attributes); | 1110 attributes); |
1111 } | 1111 } |
1112 | 1112 |
1113 // | |
1114 // Accessors::MakeModuleExport | |
1115 // | |
1116 | |
1117 static void ModuleGetExport(v8::Local<v8::Name> property, | |
1118 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1119 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | |
1120 Context* context = Context::cast(instance->context()); | |
1121 DCHECK(context->IsModuleContext()); | |
1122 Isolate* isolate = instance->GetIsolate(); | |
1123 int slot = info.Data() | |
1124 ->Int32Value(info.GetIsolate()->GetCurrentContext()) | |
1125 .FromMaybe(-1); | |
1126 if (slot < 0 || slot >= context->length()) { | |
1127 Handle<Name> name = v8::Utils::OpenHandle(*property); | |
1128 | |
1129 Handle<Object> exception = isolate->factory()->NewReferenceError( | |
1130 MessageTemplate::kNotDefined, name); | |
1131 isolate->ScheduleThrow(*exception); | |
1132 return; | |
1133 } | |
1134 Object* value = context->get(slot); | |
1135 if (value->IsTheHole(isolate)) { | |
1136 Handle<Name> name = v8::Utils::OpenHandle(*property); | |
1137 | |
1138 Handle<Object> exception = isolate->factory()->NewReferenceError( | |
1139 MessageTemplate::kNotDefined, name); | |
1140 isolate->ScheduleThrow(*exception); | |
1141 return; | |
1142 } | |
1143 info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate))); | |
1144 } | |
1145 | |
1146 | |
1147 static void ModuleSetExport(v8::Local<v8::Name> property, | |
1148 v8::Local<v8::Value> value, | |
1149 const v8::PropertyCallbackInfo<void>& info) { | |
1150 if (!info.ShouldThrowOnError()) return; | |
1151 Handle<Name> name = v8::Utils::OpenHandle(*property); | |
1152 Isolate* isolate = name->GetIsolate(); | |
1153 Handle<Object> exception = | |
1154 isolate->factory()->NewTypeError(MessageTemplate::kNotDefined, name); | |
1155 isolate->ScheduleThrow(*exception); | |
1156 } | |
1157 | |
1158 | |
1159 Handle<AccessorInfo> Accessors::MakeModuleExport( | |
1160 Handle<String> name, | |
1161 int index, | |
1162 PropertyAttributes attributes) { | |
1163 Isolate* isolate = name->GetIsolate(); | |
1164 Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport, | |
1165 &ModuleSetExport, attributes); | |
1166 info->set_data(Smi::FromInt(index)); | |
1167 return info; | |
1168 } | |
1169 | |
1170 | 1113 |
1171 } // namespace internal | 1114 } // namespace internal |
1172 } // namespace v8 | 1115 } // namespace v8 |
OLD | NEW |