OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 bool IsResourceHotForCaching(CachedMetadataHandler* cache_handler, | 253 bool IsResourceHotForCaching(CachedMetadataHandler* cache_handler, |
254 int hot_hours) { | 254 int hot_hours) { |
255 const double cache_within_seconds = hot_hours * 60 * 60; | 255 const double cache_within_seconds = hot_hours * 60 * 60; |
256 uint32_t tag = CacheTag(kCacheTagTimeStamp, cache_handler); | 256 uint32_t tag = CacheTag(kCacheTagTimeStamp, cache_handler); |
257 RefPtr<CachedMetadata> cached_metadata = | 257 RefPtr<CachedMetadata> cached_metadata = |
258 cache_handler->GetCachedMetadata(tag); | 258 cache_handler->GetCachedMetadata(tag); |
259 if (!cached_metadata) | 259 if (!cached_metadata) |
260 return false; | 260 return false; |
261 double time_stamp; | 261 double time_stamp; |
262 const int size = sizeof(time_stamp); | 262 const int size = sizeof(time_stamp); |
263 ASSERT(cached_metadata->size() == size); | 263 DCHECK_EQ(cached_metadata->size(), static_cast<unsigned long>(size)); |
264 memcpy(&time_stamp, cached_metadata->Data(), size); | 264 memcpy(&time_stamp, cached_metadata->Data(), size); |
265 return (WTF::CurrentTime() - time_stamp) < cache_within_seconds; | 265 return (WTF::CurrentTime() - time_stamp) < cache_within_seconds; |
266 } | 266 } |
267 | 267 |
268 // Final compile call for a streamed compilation. Most decisions have already | 268 // Final compile call for a streamed compilation. Most decisions have already |
269 // been made, but we need to write back data into the cache. | 269 // been made, but we need to write back data into the cache. |
270 v8::MaybeLocal<v8::Script> PostStreamCompile( | 270 v8::MaybeLocal<v8::Script> PostStreamCompile( |
271 V8CacheOptions cache_options, | 271 V8CacheOptions cache_options, |
272 CachedMetadataHandler* cache_handler, | 272 CachedMetadataHandler* cache_handler, |
273 ScriptStreamer* streamer, | 273 ScriptStreamer* streamer, |
(...skipping 28 matching lines...) Expand all Loading... |
302 break; | 302 break; |
303 } | 303 } |
304 | 304 |
305 case kV8CacheOptionsDefault: | 305 case kV8CacheOptionsDefault: |
306 case kV8CacheOptionsCode: | 306 case kV8CacheOptionsCode: |
307 V8ScriptRunner::SetCacheTimeStamp(cache_handler); | 307 V8ScriptRunner::SetCacheTimeStamp(cache_handler); |
308 break; | 308 break; |
309 | 309 |
310 case kV8CacheOptionsAlways: | 310 case kV8CacheOptionsAlways: |
311 // Currently V8CacheOptionsAlways doesn't support streaming. | 311 // Currently V8CacheOptionsAlways doesn't support streaming. |
312 ASSERT_NOT_REACHED(); | 312 NOTREACHED(); |
313 case kV8CacheOptionsNone: | 313 case kV8CacheOptionsNone: |
314 break; | 314 break; |
315 } | 315 } |
316 return script; | 316 return script; |
317 } | 317 } |
318 | 318 |
319 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, | 319 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, |
320 v8::Local<v8::String>, | 320 v8::Local<v8::String>, |
321 v8::ScriptOrigin)> | 321 v8::ScriptOrigin)> |
322 CompileFn; | 322 CompileFn; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 uint32_t code_cache_tag = CacheTag(kCacheTagCode, cache_handler); | 382 uint32_t code_cache_tag = CacheTag(kCacheTagCode, cache_handler); |
383 return Bind(CompileAndProduceCache, WrapPersistent(cache_handler), | 383 return Bind(CompileAndProduceCache, WrapPersistent(cache_handler), |
384 code_cache_tag, v8::ScriptCompiler::kProduceCodeCache, | 384 code_cache_tag, v8::ScriptCompiler::kProduceCodeCache, |
385 CachedMetadataHandler::kSendToPlatform); | 385 CachedMetadataHandler::kSendToPlatform); |
386 break; | 386 break; |
387 } | 387 } |
388 | 388 |
389 case kV8CacheOptionsNone: | 389 case kV8CacheOptionsNone: |
390 // Shouldn't happen, as this is handled above. | 390 // Shouldn't happen, as this is handled above. |
391 // Case is here so that compiler can check all cases are handled. | 391 // Case is here so that compiler can check all cases are handled. |
392 ASSERT_NOT_REACHED(); | 392 NOTREACHED(); |
393 break; | 393 break; |
394 } | 394 } |
395 | 395 |
396 // All switch branches should return and we should never get here. | 396 // All switch branches should return and we should never get here. |
397 // But some compilers aren't sure, hence this default. | 397 // But some compilers aren't sure, hence this default. |
398 ASSERT_NOT_REACHED(); | 398 NOTREACHED(); |
399 return Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable); | 399 return Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable); |
400 } | 400 } |
401 | 401 |
402 // Select a compile function for a streaming compile. | 402 // Select a compile function for a streaming compile. |
403 std::unique_ptr<CompileFn> SelectCompileFunction(V8CacheOptions cache_options, | 403 std::unique_ptr<CompileFn> SelectCompileFunction(V8CacheOptions cache_options, |
404 ScriptResource* resource, | 404 ScriptResource* resource, |
405 ScriptStreamer* streamer) { | 405 ScriptStreamer* streamer) { |
406 // We don't stream scripts which don't have a Resource. | 406 // We don't stream scripts which don't have a Resource. |
407 ASSERT(resource); | 407 DCHECK(resource); |
408 // Failed resources should never get this far. | 408 // Failed resources should never get this far. |
409 ASSERT(!resource->ErrorOccurred()); | 409 DCHECK(!resource->ErrorOccurred()); |
410 ASSERT(streamer->IsFinished()); | 410 DCHECK(streamer->IsFinished()); |
411 ASSERT(!streamer->StreamingSuppressed()); | 411 DCHECK(!streamer->StreamingSuppressed()); |
412 return WTF::Bind(PostStreamCompile, cache_options, | 412 return WTF::Bind(PostStreamCompile, cache_options, |
413 WrapPersistent(resource->CacheHandler()), | 413 WrapPersistent(resource->CacheHandler()), |
414 WrapPersistent(streamer)); | 414 WrapPersistent(streamer)); |
415 } | 415 } |
416 } // namespace | 416 } // namespace |
417 | 417 |
418 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( | 418 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( |
419 const ScriptSourceCode& source, | 419 const ScriptSourceCode& source, |
420 v8::Isolate* isolate, | 420 v8::Isolate* isolate, |
421 AccessControlStatus access_control_status, | 421 AccessControlStatus access_control_status, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 ScriptResource* resource, | 459 ScriptResource* resource, |
460 ScriptStreamer* streamer, | 460 ScriptStreamer* streamer, |
461 CachedMetadataHandler* cache_handler, | 461 CachedMetadataHandler* cache_handler, |
462 AccessControlStatus access_control_status, | 462 AccessControlStatus access_control_status, |
463 V8CacheOptions cache_options) { | 463 V8CacheOptions cache_options) { |
464 TRACE_EVENT2( | 464 TRACE_EVENT2( |
465 "v8,devtools.timeline", "v8.compile", "fileName", file_name.Utf8(), | 465 "v8,devtools.timeline", "v8.compile", "fileName", file_name.Utf8(), |
466 "data", | 466 "data", |
467 InspectorCompileScriptEvent::Data(file_name, script_start_position)); | 467 InspectorCompileScriptEvent::Data(file_name, script_start_position)); |
468 | 468 |
469 ASSERT(!streamer || resource); | 469 DCHECK(!streamer || resource); |
470 ASSERT(!resource || resource->CacheHandler() == cache_handler); | 470 DCHECK(!resource || resource->CacheHandler() == cache_handler); |
471 | 471 |
472 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at | 472 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at |
473 // 1, whereas v8 starts at 0. | 473 // 1, whereas v8 starts at 0. |
474 v8::ScriptOrigin origin( | 474 v8::ScriptOrigin origin( |
475 V8String(isolate, file_name), | 475 V8String(isolate, file_name), |
476 v8::Integer::New(isolate, script_start_position.line_.ZeroBasedInt()), | 476 v8::Integer::New(isolate, script_start_position.line_.ZeroBasedInt()), |
477 v8::Integer::New(isolate, script_start_position.column_.ZeroBasedInt()), | 477 v8::Integer::New(isolate, script_start_position.column_.ZeroBasedInt()), |
478 V8Boolean(access_control_status == kSharableCrossOrigin, isolate), | 478 V8Boolean(access_control_status == kSharableCrossOrigin, isolate), |
479 v8::Local<v8::Integer>(), V8String(isolate, source_map_url), | 479 v8::Local<v8::Integer>(), V8String(isolate, source_map_url), |
480 V8Boolean(access_control_status == kOpaqueResource, isolate)); | 480 V8Boolean(access_control_status == kOpaqueResource, isolate)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 V8Boolean(true, isolate)); // is_module | 518 V8Boolean(true, isolate)); // is_module |
519 | 519 |
520 v8::ScriptCompiler::Source script_source(V8String(isolate, source), origin); | 520 v8::ScriptCompiler::Source script_source(V8String(isolate, source), origin); |
521 return v8::ScriptCompiler::CompileModule(isolate, &script_source); | 521 return v8::ScriptCompiler::CompileModule(isolate, &script_source); |
522 } | 522 } |
523 | 523 |
524 v8::MaybeLocal<v8::Value> V8ScriptRunner::RunCompiledScript( | 524 v8::MaybeLocal<v8::Value> V8ScriptRunner::RunCompiledScript( |
525 v8::Isolate* isolate, | 525 v8::Isolate* isolate, |
526 v8::Local<v8::Script> script, | 526 v8::Local<v8::Script> script, |
527 ExecutionContext* context) { | 527 ExecutionContext* context) { |
528 ASSERT(!script.IsEmpty()); | 528 DCHECK(!script.IsEmpty()); |
529 ScopedFrameBlamer frame_blamer( | 529 ScopedFrameBlamer frame_blamer( |
530 context->IsDocument() ? ToDocument(context)->GetFrame() : nullptr); | 530 context->IsDocument() ? ToDocument(context)->GetFrame() : nullptr); |
531 TRACE_EVENT1("v8", "v8.run", "fileName", | 531 TRACE_EVENT1("v8", "v8.run", "fileName", |
532 TRACE_STR_COPY(*v8::String::Utf8Value( | 532 TRACE_STR_COPY(*v8::String::Utf8Value( |
533 script->GetUnboundScript()->GetScriptName()))); | 533 script->GetUnboundScript()->GetScriptName()))); |
534 | 534 |
535 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) | 535 if (v8::MicrotasksScope::GetCurrentDepth(isolate) >= kMaxRecursionDepth) |
536 return ThrowStackOverflowExceptionIfNeeded(isolate); | 536 return ThrowStackOverflowExceptionIfNeeded(isolate); |
537 | 537 |
538 RELEASE_ASSERT(!context->IsIteratingOverObservers()); | 538 CHECK(!context->IsIteratingOverObservers()); |
539 | 539 |
540 // Run the script and keep track of the current recursion depth. | 540 // Run the script and keep track of the current recursion depth. |
541 v8::MaybeLocal<v8::Value> result; | 541 v8::MaybeLocal<v8::Value> result; |
542 { | 542 { |
543 if (ScriptForbiddenScope::IsScriptForbidden()) { | 543 if (ScriptForbiddenScope::IsScriptForbidden()) { |
544 ThrowScriptForbiddenException(isolate); | 544 ThrowScriptForbiddenException(isolate); |
545 return v8::MaybeLocal<v8::Value>(); | 545 return v8::MaybeLocal<v8::Value>(); |
546 } | 546 } |
547 v8::MicrotasksScope microtasks_scope(isolate, | 547 v8::MicrotasksScope microtasks_scope(isolate, |
548 v8::MicrotasksScope::kRunMicrotasks); | 548 v8::MicrotasksScope::kRunMicrotasks); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 LocalFrame* frame = | 631 LocalFrame* frame = |
632 context->IsDocument() ? ToDocument(context)->GetFrame() : nullptr; | 632 context->IsDocument() ? ToDocument(context)->GetFrame() : nullptr; |
633 ScopedFrameBlamer frame_blamer(frame); | 633 ScopedFrameBlamer frame_blamer(frame); |
634 TRACE_EVENT0("v8", "v8.callFunction"); | 634 TRACE_EVENT0("v8", "v8.callFunction"); |
635 | 635 |
636 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); | 636 int depth = v8::MicrotasksScope::GetCurrentDepth(isolate); |
637 if (depth >= kMaxRecursionDepth) | 637 if (depth >= kMaxRecursionDepth) |
638 return v8::MaybeLocal<v8::Value>( | 638 return v8::MaybeLocal<v8::Value>( |
639 ThrowStackOverflowExceptionIfNeeded(isolate)); | 639 ThrowStackOverflowExceptionIfNeeded(isolate)); |
640 | 640 |
641 RELEASE_ASSERT(!context->IsIteratingOverObservers()); | 641 CHECK(!context->IsIteratingOverObservers()); |
642 | 642 |
643 if (ScriptForbiddenScope::IsScriptForbidden()) { | 643 if (ScriptForbiddenScope::IsScriptForbidden()) { |
644 ThrowScriptForbiddenException(isolate); | 644 ThrowScriptForbiddenException(isolate); |
645 return v8::MaybeLocal<v8::Value>(); | 645 return v8::MaybeLocal<v8::Value>(); |
646 } | 646 } |
647 | 647 |
648 DCHECK(!frame || BindingSecurity::ShouldAllowAccessToFrame( | 648 DCHECK(!frame || BindingSecurity::ShouldAllowAccessToFrame( |
649 ToLocalDOMWindow(function->CreationContext()), frame, | 649 ToLocalDOMWindow(function->CreationContext()), frame, |
650 BindingSecurity::ErrorReportOption::kDoNotReport)); | 650 BindingSecurity::ErrorReportOption::kDoNotReport)); |
651 CHECK(!ThreadState::Current()->IsWrapperTracingForbidden()); | 651 CHECK(!ThreadState::Current()->IsWrapperTracingForbidden()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 V8AtomicString(isolate, "((e) => { throw e; })"), origin) | 723 V8AtomicString(isolate, "((e) => { throw e; })"), origin) |
724 .ToLocalChecked(); | 724 .ToLocalChecked(); |
725 v8::Local<v8::Function> thrower = RunCompiledInternalScript(isolate, script) | 725 v8::Local<v8::Function> thrower = RunCompiledInternalScript(isolate, script) |
726 .ToLocalChecked() | 726 .ToLocalChecked() |
727 .As<v8::Function>(); | 727 .As<v8::Function>(); |
728 v8::Local<v8::Value> args[] = {exception}; | 728 v8::Local<v8::Value> args[] = {exception}; |
729 CallInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); | 729 CallInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); |
730 } | 730 } |
731 | 731 |
732 } // namespace blink | 732 } // namespace blink |
OLD | NEW |