OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate); | 263 Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate); |
264 desc->MarkAsUndetectable(); | 264 desc->MarkAsUndetectable(); |
265 Local<v8::Object> obj; | 265 Local<v8::Object> obj; |
266 if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) { | 266 if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) { |
267 return nullptr; | 267 return nullptr; |
268 } | 268 } |
269 return *Utils::OpenHandle(*obj); | 269 return *Utils::OpenHandle(*obj); |
270 } | 270 } |
271 | 271 |
| 272 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 273 double v1 = args[0] |
| 274 ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext()) |
| 275 .ToChecked(); |
| 276 double v2 = args[1] |
| 277 ->NumberValue(v8::Isolate::GetCurrent()->GetCurrentContext()) |
| 278 .ToChecked(); |
| 279 args.GetReturnValue().Set( |
| 280 v8::Number::New(v8::Isolate::GetCurrent(), v1 - v2)); |
| 281 } |
| 282 |
| 283 // Returns a callable object. The object returns the difference of its two |
| 284 // parameters when it is called. |
| 285 RUNTIME_FUNCTION(Runtime_GetCallable) { |
| 286 HandleScope scope(isolate); |
| 287 DCHECK(args.length() == 0); |
| 288 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 289 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(v8_isolate); |
| 290 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 291 instance_template->SetCallAsFunctionHandler(call_as_function); |
| 292 v8_isolate->GetCurrentContext(); |
| 293 Local<v8::Object> instance = |
| 294 t->GetFunction(v8_isolate->GetCurrentContext()) |
| 295 .ToLocalChecked() |
| 296 ->NewInstance(v8_isolate->GetCurrentContext()) |
| 297 .ToLocalChecked(); |
| 298 return *Utils::OpenHandle(*instance); |
| 299 } |
272 | 300 |
273 RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) { | 301 RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) { |
274 HandleScope scope(isolate); | 302 HandleScope scope(isolate); |
275 DCHECK(args.length() == 1); | 303 DCHECK(args.length() == 1); |
276 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 304 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
277 function->ClearTypeFeedbackInfo(); | 305 function->ClearTypeFeedbackInfo(); |
278 Code* unoptimized = function->shared()->code(); | 306 Code* unoptimized = function->shared()->code(); |
279 if (unoptimized->kind() == Code::FUNCTION) { | 307 if (unoptimized->kind() == Code::FUNCTION) { |
280 unoptimized->ClearInlineCaches(); | 308 unoptimized->ClearInlineCaches(); |
281 } | 309 } |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 664 |
637 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { | 665 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { |
638 SealHandleScope shs(isolate); | 666 SealHandleScope shs(isolate); |
639 DCHECK_EQ(0, args.length()); | 667 DCHECK_EQ(0, args.length()); |
640 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); | 668 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); |
641 } | 669 } |
642 | 670 |
643 | 671 |
644 } // namespace internal | 672 } // namespace internal |
645 } // namespace v8 | 673 } // namespace v8 |
OLD | NEW |