OLD | NEW |
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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 ASSERT(callback->IsCompatibleReceiver(recv)); | 1098 ASSERT(callback->IsCompatibleReceiver(recv)); |
1099 Handle<Name> name = args.at<Name>(2); | 1099 Handle<Name> name = args.at<Name>(2); |
1100 Handle<Object> value = args.at<Object>(3); | 1100 Handle<Object> value = args.at<Object>(3); |
1101 HandleScope scope(isolate); | 1101 HandleScope scope(isolate); |
1102 | 1102 |
1103 // TODO(rossberg): Support symbols in the API. | 1103 // TODO(rossberg): Support symbols in the API. |
1104 if (name->IsSymbol()) return *value; | 1104 if (name->IsSymbol()) return *value; |
1105 Handle<String> str = Handle<String>::cast(name); | 1105 Handle<String> str = Handle<String>::cast(name); |
1106 | 1106 |
1107 LOG(isolate, ApiNamedPropertyAccess("store", recv, *name)); | 1107 LOG(isolate, ApiNamedPropertyAccess("store", recv, *name)); |
1108 CustomArguments custom_args(isolate, callback->data(), recv, recv); | 1108 PropertyCallbackArguments |
1109 v8::AccessorInfo info(custom_args.end()); | 1109 custom_args(isolate, callback->data(), recv, recv); |
1110 { | 1110 { |
1111 // Leaving JavaScript. | 1111 // Leaving JavaScript. |
1112 VMState<EXTERNAL> state(isolate); | 1112 VMState<EXTERNAL> state(isolate); |
1113 ExternalCallbackScope call_scope(isolate, setter_address); | 1113 ExternalCallbackScope call_scope(isolate, setter_address); |
1114 fun(v8::Utils::ToLocal(str), v8::Utils::ToLocal(value), info); | 1114 custom_args.Call(fun, v8::Utils::ToLocal(str), v8::Utils::ToLocal(value)); |
1115 } | 1115 } |
1116 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1116 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
1117 return *value; | 1117 return *value; |
1118 } | 1118 } |
1119 | 1119 |
1120 | 1120 |
1121 static const int kAccessorInfoOffsetInInterceptorArgs = 2; | 1121 static const int kAccessorInfoOffsetInInterceptorArgs = 2; |
1122 | 1122 |
1123 | 1123 |
1124 /** | 1124 /** |
1125 * Attempts to load a property with an interceptor (which must be present), | 1125 * Attempts to load a property with an interceptor (which must be present), |
1126 * but doesn't search the prototype chain. | 1126 * but doesn't search the prototype chain. |
1127 * | 1127 * |
1128 * Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't | 1128 * Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't |
1129 * provide any value for the given name. | 1129 * provide any value for the given name. |
1130 */ | 1130 */ |
1131 RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) { | 1131 RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) { |
| 1132 typedef PropertyCallbackArguments PCA; |
| 1133 static const int kArgsOffset = kAccessorInfoOffsetInInterceptorArgs; |
1132 Handle<Name> name_handle = args.at<Name>(0); | 1134 Handle<Name> name_handle = args.at<Name>(0); |
1133 Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1); | 1135 Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1); |
1134 ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); | 1136 ASSERT(kArgsOffset == 2); |
1135 ASSERT(args[2]->IsJSObject()); // Receiver. | 1137 // No ReturnValue in interceptors. |
1136 ASSERT(args[3]->IsJSObject()); // Holder. | 1138 ASSERT(args.length() == kArgsOffset + PCA::kArgsLength - 1); |
1137 ASSERT(args[5]->IsSmi()); // Isolate. | |
1138 ASSERT(args.length() == 6); | |
1139 | 1139 |
1140 // TODO(rossberg): Support symbols in the API. | 1140 // TODO(rossberg): Support symbols in the API. |
1141 if (name_handle->IsSymbol()) | 1141 if (name_handle->IsSymbol()) |
1142 return isolate->heap()->no_interceptor_result_sentinel(); | 1142 return isolate->heap()->no_interceptor_result_sentinel(); |
1143 Handle<String> name = Handle<String>::cast(name_handle); | 1143 Handle<String> name = Handle<String>::cast(name_handle); |
1144 | 1144 |
1145 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); | 1145 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); |
1146 v8::NamedPropertyGetter getter = | 1146 v8::NamedPropertyGetter getter = |
1147 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); | 1147 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); |
1148 ASSERT(getter != NULL); | 1148 ASSERT(getter != NULL); |
1149 | 1149 |
| 1150 Handle<JSObject> receiver = |
| 1151 args.at<JSObject>(kArgsOffset - PCA::kThisIndex); |
| 1152 Handle<JSObject> holder = |
| 1153 args.at<JSObject>(kArgsOffset - PCA::kHolderIndex); |
| 1154 PropertyCallbackArguments callback_args(isolate, |
| 1155 interceptor_info->data(), |
| 1156 *receiver, |
| 1157 *holder); |
1150 { | 1158 { |
1151 // Use the interceptor getter. | 1159 // Use the interceptor getter. |
1152 v8::AccessorInfo info(args.arguments() - | |
1153 kAccessorInfoOffsetInInterceptorArgs); | |
1154 HandleScope scope(isolate); | 1160 HandleScope scope(isolate); |
1155 v8::Handle<v8::Value> r; | 1161 v8::Handle<v8::Value> r; |
1156 { | 1162 { |
1157 // Leaving JavaScript. | 1163 // Leaving JavaScript. |
1158 VMState<EXTERNAL> state(isolate); | 1164 VMState<EXTERNAL> state(isolate); |
1159 r = getter(v8::Utils::ToLocal(name), info); | 1165 r = callback_args.Call(getter, v8::Utils::ToLocal(name)); |
1160 } | 1166 } |
1161 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1167 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
1162 if (!r.IsEmpty()) { | 1168 if (!r.IsEmpty()) { |
1163 Handle<Object> result = v8::Utils::OpenHandle(*r); | 1169 Handle<Object> result = v8::Utils::OpenHandle(*r); |
1164 result->VerifyApiCallResultType(); | 1170 result->VerifyApiCallResultType(); |
1165 return *v8::Utils::OpenHandle(*r); | 1171 return *v8::Utils::OpenHandle(*r); |
1166 } | 1172 } |
1167 } | 1173 } |
1168 | 1174 |
1169 return isolate->heap()->no_interceptor_result_sentinel(); | 1175 return isolate->heap()->no_interceptor_result_sentinel(); |
(...skipping 13 matching lines...) Expand all Loading... |
1183 Handle<Name> name_handle(name); | 1189 Handle<Name> name_handle(name); |
1184 Handle<Object> error = | 1190 Handle<Object> error = |
1185 FACTORY->NewReferenceError("not_defined", | 1191 FACTORY->NewReferenceError("not_defined", |
1186 HandleVector(&name_handle, 1)); | 1192 HandleVector(&name_handle, 1)); |
1187 return isolate->Throw(*error); | 1193 return isolate->Throw(*error); |
1188 } | 1194 } |
1189 | 1195 |
1190 | 1196 |
1191 static MaybeObject* LoadWithInterceptor(Arguments* args, | 1197 static MaybeObject* LoadWithInterceptor(Arguments* args, |
1192 PropertyAttributes* attrs) { | 1198 PropertyAttributes* attrs) { |
| 1199 typedef PropertyCallbackArguments PCA; |
| 1200 static const int kArgsOffset = kAccessorInfoOffsetInInterceptorArgs; |
1193 Handle<Name> name_handle = args->at<Name>(0); | 1201 Handle<Name> name_handle = args->at<Name>(0); |
1194 Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1); | 1202 Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1); |
1195 ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); | 1203 ASSERT(kArgsOffset == 2); |
1196 Handle<JSObject> receiver_handle = args->at<JSObject>(2); | 1204 // No ReturnValue in interceptors. |
1197 Handle<JSObject> holder_handle = args->at<JSObject>(3); | 1205 ASSERT(args->length() == kArgsOffset + PCA::kArgsLength - 1); |
1198 ASSERT(args->length() == 6); | 1206 Handle<JSObject> receiver_handle = |
| 1207 args->at<JSObject>(kArgsOffset - PCA::kThisIndex); |
| 1208 Handle<JSObject> holder_handle = |
| 1209 args->at<JSObject>(kArgsOffset - PCA::kHolderIndex); |
1199 | 1210 |
1200 Isolate* isolate = receiver_handle->GetIsolate(); | 1211 Isolate* isolate = receiver_handle->GetIsolate(); |
1201 | 1212 |
1202 // TODO(rossberg): Support symbols in the API. | 1213 // TODO(rossberg): Support symbols in the API. |
1203 if (name_handle->IsSymbol()) | 1214 if (name_handle->IsSymbol()) |
1204 return holder_handle->GetPropertyPostInterceptor( | 1215 return holder_handle->GetPropertyPostInterceptor( |
1205 *receiver_handle, *name_handle, attrs); | 1216 *receiver_handle, *name_handle, attrs); |
1206 Handle<String> name = Handle<String>::cast(name_handle); | 1217 Handle<String> name = Handle<String>::cast(name_handle); |
1207 | 1218 |
1208 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); | 1219 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); |
1209 v8::NamedPropertyGetter getter = | 1220 v8::NamedPropertyGetter getter = |
1210 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); | 1221 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); |
1211 ASSERT(getter != NULL); | 1222 ASSERT(getter != NULL); |
1212 | 1223 |
| 1224 PropertyCallbackArguments callback_args(isolate, |
| 1225 interceptor_info->data(), |
| 1226 *receiver_handle, |
| 1227 *holder_handle); |
1213 { | 1228 { |
1214 // Use the interceptor getter. | 1229 // Use the interceptor getter. |
1215 v8::AccessorInfo info(args->arguments() - | |
1216 kAccessorInfoOffsetInInterceptorArgs); | |
1217 HandleScope scope(isolate); | 1230 HandleScope scope(isolate); |
1218 v8::Handle<v8::Value> r; | 1231 v8::Handle<v8::Value> r; |
1219 { | 1232 { |
1220 // Leaving JavaScript. | 1233 // Leaving JavaScript. |
1221 VMState<EXTERNAL> state(isolate); | 1234 VMState<EXTERNAL> state(isolate); |
1222 r = getter(v8::Utils::ToLocal(name), info); | 1235 r = callback_args.Call(getter, v8::Utils::ToLocal(name)); |
1223 } | 1236 } |
1224 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1237 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
1225 if (!r.IsEmpty()) { | 1238 if (!r.IsEmpty()) { |
1226 *attrs = NONE; | 1239 *attrs = NONE; |
1227 Handle<Object> result = v8::Utils::OpenHandle(*r); | 1240 Handle<Object> result = v8::Utils::OpenHandle(*r); |
1228 result->VerifyApiCallResultType(); | 1241 result->VerifyApiCallResultType(); |
1229 return *result; | 1242 return *result; |
1230 } | 1243 } |
1231 } | 1244 } |
1232 | 1245 |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 Handle<FunctionTemplateInfo>( | 2101 Handle<FunctionTemplateInfo>( |
2089 FunctionTemplateInfo::cast(signature->receiver())); | 2102 FunctionTemplateInfo::cast(signature->receiver())); |
2090 } | 2103 } |
2091 } | 2104 } |
2092 | 2105 |
2093 is_simple_api_call_ = true; | 2106 is_simple_api_call_ = true; |
2094 } | 2107 } |
2095 | 2108 |
2096 | 2109 |
2097 } } // namespace v8::internal | 2110 } } // namespace v8::internal |
OLD | NEW |