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

Side by Side Diff: src/runtime.cc

Issue 669061: First take on custom call generators. (Closed)
Patch Set: Ultimate version Created 10 years, 9 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
« no previous file with comments | « src/runtime.h ('k') | src/stub-cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 HandleScope scope; 1231 HandleScope scope;
1232 ASSERT(args.length() == 1); 1232 ASSERT(args.length() == 1);
1233 CONVERT_ARG_CHECKED(JSArray, prototype, 0); 1233 CONVERT_ARG_CHECKED(JSArray, prototype, 0);
1234 // This is necessary to enable fast checks for absence of elements 1234 // This is necessary to enable fast checks for absence of elements
1235 // on Array.prototype and below. 1235 // on Array.prototype and below.
1236 prototype->set_elements(Heap::empty_fixed_array()); 1236 prototype->set_elements(Heap::empty_fixed_array());
1237 return Smi::FromInt(0); 1237 return Smi::FromInt(0);
1238 } 1238 }
1239 1239
1240 1240
1241 static void SetCustomCallGenerator(Handle<JSFunction> function,
1242 CustomCallGenerator generator) {
1243 if (function->shared()->function_data()->IsUndefined()) {
1244 function->shared()->set_function_data(*FromCData(generator));
1245 }
1246 }
1247
1248
1249 static Handle<JSFunction> InstallBuiltin(Handle<JSObject> holder,
1250 const char* name,
1251 Builtins::Name builtin_name,
1252 CustomCallGenerator generator = NULL) {
1253 Handle<String> key = Factory::LookupAsciiSymbol(name);
1254 Handle<Code> code(Builtins::builtin(builtin_name));
1255 Handle<JSFunction> optimized = Factory::NewFunction(key,
1256 JS_OBJECT_TYPE,
1257 JSObject::kHeaderSize,
1258 code,
1259 false);
1260 optimized->shared()->DontAdaptArguments();
1261 if (generator != NULL) {
1262 SetCustomCallGenerator(optimized, generator);
1263 }
1264 SetProperty(holder, key, optimized, NONE);
1265 return optimized;
1266 }
1267
1268
1269 static Object* CompileArrayPushCall(CallStubCompiler* compiler,
1270 Object* object,
1271 JSObject* holder,
1272 JSFunction* function,
1273 String* name,
1274 StubCompiler::CheckType check) {
1275 return compiler->CompileArrayPushCall(object, holder, function, name, check);
1276 }
1277
1278
1279 static Object* Runtime_SpecialArrayFunctions(Arguments args) {
1280 HandleScope scope;
1281 ASSERT(args.length() == 1);
1282 CONVERT_ARG_CHECKED(JSObject, holder, 0);
1283
1284 InstallBuiltin(holder, "pop", Builtins::ArrayPop);
1285 InstallBuiltin(holder, "push", Builtins::ArrayPush, CompileArrayPushCall);
1286 InstallBuiltin(holder, "shift", Builtins::ArrayShift);
1287 InstallBuiltin(holder, "unshift", Builtins::ArrayUnshift);
1288 InstallBuiltin(holder, "slice", Builtins::ArraySlice);
1289 InstallBuiltin(holder, "splice", Builtins::ArraySplice);
1290
1291 return *holder;
1292 }
1293
1294
1241 static Object* Runtime_MaterializeRegExpLiteral(Arguments args) { 1295 static Object* Runtime_MaterializeRegExpLiteral(Arguments args) {
1242 HandleScope scope; 1296 HandleScope scope;
1243 ASSERT(args.length() == 4); 1297 ASSERT(args.length() == 4);
1244 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 1298 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
1245 int index = Smi::cast(args[1])->value(); 1299 int index = Smi::cast(args[1])->value();
1246 Handle<String> pattern = args.at<String>(2); 1300 Handle<String> pattern = args.at<String>(2);
1247 Handle<String> flags = args.at<String>(3); 1301 Handle<String> flags = args.at<String>(3);
1248 1302
1249 // Get the RegExp function from the context in the literals array. 1303 // Get the RegExp function from the context in the literals array.
1250 // This is the RegExp function from the context in which the 1304 // This is the RegExp function from the context in which the
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 if (obj->IsFailure()) return obj; 1419 if (obj->IsFailure()) return obj;
1366 return args[0]; // return TOS 1420 return args[0]; // return TOS
1367 } 1421 }
1368 1422
1369 1423
1370 static Object* Runtime_FunctionIsAPIFunction(Arguments args) { 1424 static Object* Runtime_FunctionIsAPIFunction(Arguments args) {
1371 NoHandleAllocation ha; 1425 NoHandleAllocation ha;
1372 ASSERT(args.length() == 1); 1426 ASSERT(args.length() == 1);
1373 1427
1374 CONVERT_CHECKED(JSFunction, f, args[0]); 1428 CONVERT_CHECKED(JSFunction, f, args[0]);
1375 // The function_data field of the shared function info is used exclusively by 1429 return f->shared()->IsApiFunction() ? Heap::true_value()
1376 // the API. 1430 : Heap::false_value();
1377 return !f->shared()->function_data()->IsUndefined() ? Heap::true_value()
1378 : Heap::false_value();
1379 } 1431 }
1380 1432
1381 static Object* Runtime_FunctionIsBuiltin(Arguments args) { 1433 static Object* Runtime_FunctionIsBuiltin(Arguments args) {
1382 NoHandleAllocation ha; 1434 NoHandleAllocation ha;
1383 ASSERT(args.length() == 1); 1435 ASSERT(args.length() == 1);
1384 1436
1385 CONVERT_CHECKED(JSFunction, f, args[0]); 1437 CONVERT_CHECKED(JSFunction, f, args[0]);
1386 return f->IsBuiltin() ? Heap::true_value() : Heap::false_value(); 1438 return f->IsBuiltin() ? Heap::true_value() : Heap::false_value();
1387 } 1439 }
1388 1440
(...skipping 7356 matching lines...) Expand 10 before | Expand all | Expand 10 after
8745 } else { 8797 } else {
8746 // Handle last resort GC and make sure to allow future allocations 8798 // Handle last resort GC and make sure to allow future allocations
8747 // to grow the heap without causing GCs (if possible). 8799 // to grow the heap without causing GCs (if possible).
8748 Counters::gc_last_resort_from_js.Increment(); 8800 Counters::gc_last_resort_from_js.Increment();
8749 Heap::CollectAllGarbage(false); 8801 Heap::CollectAllGarbage(false);
8750 } 8802 }
8751 } 8803 }
8752 8804
8753 8805
8754 } } // namespace v8::internal 8806 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/stub-cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698