Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/stub-cache.cc

Issue 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 ASSERT(callback->IsCompatibleReceiver(recv)); 1100 ASSERT(callback->IsCompatibleReceiver(recv));
1101 Handle<Name> name = args.at<Name>(2); 1101 Handle<Name> name = args.at<Name>(2);
1102 Handle<Object> value = args.at<Object>(3); 1102 Handle<Object> value = args.at<Object>(3);
1103 HandleScope scope(isolate); 1103 HandleScope scope(isolate);
1104 1104
1105 // TODO(rossberg): Support symbols in the API. 1105 // TODO(rossberg): Support symbols in the API.
1106 if (name->IsSymbol()) return *value; 1106 if (name->IsSymbol()) return *value;
1107 Handle<String> str = Handle<String>::cast(name); 1107 Handle<String> str = Handle<String>::cast(name);
1108 1108
1109 LOG(isolate, ApiNamedPropertyAccess("store", recv, *name)); 1109 LOG(isolate, ApiNamedPropertyAccess("store", recv, *name));
1110 CustomArguments custom_args(isolate, callback->data(), recv, recv); 1110 PropertyCallbackArguments
1111 v8::AccessorInfo info(custom_args.end()); 1111 custom_args(isolate, callback->data(), recv, recv);
1112 v8::AccessorInfo info = custom_args.NewInfo();
1112 { 1113 {
1113 // Leaving JavaScript. 1114 // Leaving JavaScript.
1114 VMState<EXTERNAL> state(isolate); 1115 VMState<EXTERNAL> state(isolate);
1115 ExternalCallbackScope call_scope(isolate, setter_address); 1116 ExternalCallbackScope call_scope(isolate, setter_address);
1116 fun(v8::Utils::ToLocal(str), v8::Utils::ToLocal(value), info); 1117 fun(v8::Utils::ToLocal(str), v8::Utils::ToLocal(value), info);
1117 } 1118 }
1118 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 1119 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
1119 return *value; 1120 return *value;
1120 } 1121 }
1121 1122
1122 1123
1123 static const int kAccessorInfoOffsetInInterceptorArgs = 2; 1124 static const int kAccessorInfoOffsetInInterceptorArgs = 2;
1124 1125
1125 1126
1126 /** 1127 /**
1127 * Attempts to load a property with an interceptor (which must be present), 1128 * Attempts to load a property with an interceptor (which must be present),
1128 * but doesn't search the prototype chain. 1129 * but doesn't search the prototype chain.
1129 * 1130 *
1130 * Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't 1131 * Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't
1131 * provide any value for the given name. 1132 * provide any value for the given name.
1132 */ 1133 */
1133 RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) { 1134 RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) {
1135 typedef PropertyCallbackArguments PCA;
1136 static const int kArgsOffset = kAccessorInfoOffsetInInterceptorArgs;
1134 Handle<Name> name_handle = args.at<Name>(0); 1137 Handle<Name> name_handle = args.at<Name>(0);
1135 Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1); 1138 Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1);
1136 ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); 1139 ASSERT(kArgsOffset == 2);
1137 ASSERT(args[2]->IsJSObject()); // Receiver. 1140 // No ReturnValue in interceptors.
1138 ASSERT(args[3]->IsJSObject()); // Holder. 1141 ASSERT(args.length() == kArgsOffset + PCA::kArgsLength - 1);
1139 ASSERT(args[5]->IsSmi()); // Isolate.
1140 ASSERT(args.length() == 6);
1141 1142
1142 // TODO(rossberg): Support symbols in the API. 1143 // TODO(rossberg): Support symbols in the API.
1143 if (name_handle->IsSymbol()) 1144 if (name_handle->IsSymbol())
1144 return isolate->heap()->no_interceptor_result_sentinel(); 1145 return isolate->heap()->no_interceptor_result_sentinel();
1145 Handle<String> name = Handle<String>::cast(name_handle); 1146 Handle<String> name = Handle<String>::cast(name_handle);
1146 1147
1147 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); 1148 Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
1148 v8::NamedPropertyGetter getter = 1149 v8::NamedPropertyGetter getter =
1149 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); 1150 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address);
1150 ASSERT(getter != NULL); 1151 ASSERT(getter != NULL);
1151 1152
1153 Handle<JSObject> receiver =
1154 args.at<JSObject>(kArgsOffset - PCA::kThisIndex);
1155 Handle<JSObject> holder =
1156 args.at<JSObject>(kArgsOffset - PCA::kHolderIndex);
1157 PropertyCallbackArguments callback_args(isolate,
1158 interceptor_info->data(),
1159 *receiver,
1160 *holder);
1152 { 1161 {
1153 // Use the interceptor getter. 1162 // Use the interceptor getter.
1154 v8::AccessorInfo info(args.arguments() - 1163 v8::AccessorInfo info = callback_args.NewInfo();
1155 kAccessorInfoOffsetInInterceptorArgs);
1156 HandleScope scope(isolate); 1164 HandleScope scope(isolate);
1157 v8::Handle<v8::Value> r; 1165 v8::Handle<v8::Value> r;
1158 { 1166 {
1159 // Leaving JavaScript. 1167 // Leaving JavaScript.
1160 VMState<EXTERNAL> state(isolate); 1168 VMState<EXTERNAL> state(isolate);
1161 r = getter(v8::Utils::ToLocal(name), info); 1169 r = callback_args.GetCallbackResult(
1170 isolate,
1171 getter,
1172 getter(v8::Utils::ToLocal(name), info));
1162 } 1173 }
1163 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 1174 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
1164 if (!r.IsEmpty()) { 1175 if (!r.IsEmpty()) {
1165 Handle<Object> result = v8::Utils::OpenHandle(*r); 1176 Handle<Object> result = v8::Utils::OpenHandle(*r);
1166 result->VerifyApiCallResultType(); 1177 result->VerifyApiCallResultType();
1167 return *v8::Utils::OpenHandle(*r); 1178 return *v8::Utils::OpenHandle(*r);
1168 } 1179 }
1169 } 1180 }
1170 1181
1171 return isolate->heap()->no_interceptor_result_sentinel(); 1182 return isolate->heap()->no_interceptor_result_sentinel();
(...skipping 13 matching lines...) Expand all
1185 Handle<Name> name_handle(name); 1196 Handle<Name> name_handle(name);
1186 Handle<Object> error = 1197 Handle<Object> error =
1187 FACTORY->NewReferenceError("not_defined", 1198 FACTORY->NewReferenceError("not_defined",
1188 HandleVector(&name_handle, 1)); 1199 HandleVector(&name_handle, 1));
1189 return isolate->Throw(*error); 1200 return isolate->Throw(*error);
1190 } 1201 }
1191 1202
1192 1203
1193 static MaybeObject* LoadWithInterceptor(Arguments* args, 1204 static MaybeObject* LoadWithInterceptor(Arguments* args,
1194 PropertyAttributes* attrs) { 1205 PropertyAttributes* attrs) {
1206 typedef PropertyCallbackArguments PCA;
1207 static const int kArgsOffset = kAccessorInfoOffsetInInterceptorArgs;
1195 Handle<Name> name_handle = args->at<Name>(0); 1208 Handle<Name> name_handle = args->at<Name>(0);
1196 Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1); 1209 Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1);
1197 ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); 1210 ASSERT(kArgsOffset == 2);
1198 Handle<JSObject> receiver_handle = args->at<JSObject>(2); 1211 // No ReturnValue in interceptors.
1199 Handle<JSObject> holder_handle = args->at<JSObject>(3); 1212 ASSERT(args->length() == kArgsOffset + PCA::kArgsLength - 1);
1200 ASSERT(args->length() == 6); 1213 Handle<JSObject> receiver_handle =
1214 args->at<JSObject>(kArgsOffset - PCA::kThisIndex);
1215 Handle<JSObject> holder_handle =
1216 args->at<JSObject>(kArgsOffset - PCA::kHolderIndex);
1201 1217
1202 Isolate* isolate = receiver_handle->GetIsolate(); 1218 Isolate* isolate = receiver_handle->GetIsolate();
1203 1219
1204 // TODO(rossberg): Support symbols in the API. 1220 // TODO(rossberg): Support symbols in the API.
1205 if (name_handle->IsSymbol()) 1221 if (name_handle->IsSymbol())
1206 return holder_handle->GetPropertyPostInterceptor( 1222 return holder_handle->GetPropertyPostInterceptor(
1207 *receiver_handle, *name_handle, attrs); 1223 *receiver_handle, *name_handle, attrs);
1208 Handle<String> name = Handle<String>::cast(name_handle); 1224 Handle<String> name = Handle<String>::cast(name_handle);
1209 1225
1210 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); 1226 Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
1211 v8::NamedPropertyGetter getter = 1227 v8::NamedPropertyGetter getter =
1212 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); 1228 FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address);
1213 ASSERT(getter != NULL); 1229 ASSERT(getter != NULL);
1214 1230
1231 PropertyCallbackArguments callback_args(isolate,
1232 interceptor_info->data(),
1233 *receiver_handle,
1234 *holder_handle);
1215 { 1235 {
1216 // Use the interceptor getter. 1236 // Use the interceptor getter.
1217 v8::AccessorInfo info(args->arguments() - 1237 v8::AccessorInfo info = callback_args.NewInfo();
1218 kAccessorInfoOffsetInInterceptorArgs);
1219 HandleScope scope(isolate); 1238 HandleScope scope(isolate);
1220 v8::Handle<v8::Value> r; 1239 v8::Handle<v8::Value> r;
1221 { 1240 {
1222 // Leaving JavaScript. 1241 // Leaving JavaScript.
1223 VMState<EXTERNAL> state(isolate); 1242 VMState<EXTERNAL> state(isolate);
1224 r = getter(v8::Utils::ToLocal(name), info); 1243 r = callback_args.GetCallbackResult(
1244 isolate,
1245 getter,
1246 getter(v8::Utils::ToLocal(name), info));
1225 } 1247 }
1226 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 1248 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
1227 if (!r.IsEmpty()) { 1249 if (!r.IsEmpty()) {
1228 *attrs = NONE; 1250 *attrs = NONE;
1229 Handle<Object> result = v8::Utils::OpenHandle(*r); 1251 Handle<Object> result = v8::Utils::OpenHandle(*r);
1230 result->VerifyApiCallResultType(); 1252 result->VerifyApiCallResultType();
1231 return *result; 1253 return *result;
1232 } 1254 }
1233 } 1255 }
1234 1256
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 Handle<FunctionTemplateInfo>( 2121 Handle<FunctionTemplateInfo>(
2100 FunctionTemplateInfo::cast(signature->receiver())); 2122 FunctionTemplateInfo::cast(signature->receiver()));
2101 } 2123 }
2102 } 2124 }
2103 2125
2104 is_simple_api_call_ = true; 2126 is_simple_api_call_ = true;
2105 } 2127 }
2106 2128
2107 2129
2108 } } // namespace v8::internal 2130 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/x64/macro-assembler-x64.h » ('j') | src/x64/macro-assembler-x64.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698