| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 level = InfoMessageLevel; | 136 level = InfoMessageLevel; |
| 137 break; | 137 break; |
| 138 case v8::Isolate::kMessageError: | 138 case v8::Isolate::kMessageError: |
| 139 level = InfoMessageLevel; | 139 level = InfoMessageLevel; |
| 140 break; | 140 break; |
| 141 default: | 141 default: |
| 142 NOTREACHED(); | 142 NOTREACHED(); |
| 143 } | 143 } |
| 144 return level; | 144 return level; |
| 145 } | 145 } |
| 146 |
| 147 const size_t kWasmWireBytesLimit = 1 << 12; |
| 148 |
| 146 } // namespace | 149 } // namespace |
| 147 | 150 |
| 148 void V8Initializer::messageHandlerInMainThread(v8::Local<v8::Message> message, | 151 void V8Initializer::messageHandlerInMainThread(v8::Local<v8::Message> message, |
| 149 v8::Local<v8::Value> data) { | 152 v8::Local<v8::Value> data) { |
| 150 ASSERT(isMainThread()); | 153 ASSERT(isMainThread()); |
| 151 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 154 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 152 | 155 |
| 153 if (isolate->GetEnteredContext().IsEmpty()) | 156 if (isolate->GetEnteredContext().IsEmpty()) |
| 154 return; | 157 return; |
| 155 | 158 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (ExecutionContext* executionContext = toExecutionContext(context)) { | 316 if (ExecutionContext* executionContext = toExecutionContext(context)) { |
| 314 if (ContentSecurityPolicy* policy = | 317 if (ContentSecurityPolicy* policy = |
| 315 toDocument(executionContext)->contentSecurityPolicy()) | 318 toDocument(executionContext)->contentSecurityPolicy()) |
| 316 return policy->allowEval(ScriptState::from(context), | 319 return policy->allowEval(ScriptState::from(context), |
| 317 ContentSecurityPolicy::SendReport, | 320 ContentSecurityPolicy::SendReport, |
| 318 ContentSecurityPolicy::WillThrowException); | 321 ContentSecurityPolicy::WillThrowException); |
| 319 } | 322 } |
| 320 return false; | 323 return false; |
| 321 } | 324 } |
| 322 | 325 |
| 326 static bool allowWasmCompileCallbackInMainThread(v8::Isolate* isolate, |
| 327 v8::Local<v8::Value> source, |
| 328 bool asPromise) { |
| 329 // We allow async compilation irrespective of buffer size. |
| 330 if (asPromise) |
| 331 return true; |
| 332 if (source->IsArrayBuffer() && |
| 333 v8::Local<v8::ArrayBuffer>::Cast(source)->ByteLength() > |
| 334 kWasmWireBytesLimit) { |
| 335 return false; |
| 336 } |
| 337 if (source->IsArrayBufferView() && |
| 338 v8::Local<v8::ArrayBufferView>::Cast(source)->ByteLength() > |
| 339 kWasmWireBytesLimit) { |
| 340 return false; |
| 341 } |
| 342 return true; |
| 343 } |
| 344 |
| 345 static bool allowWasmInstantiateCallbackInMainThread( |
| 346 v8::Isolate* isolate, |
| 347 v8::Local<v8::Value> source, |
| 348 v8::MaybeLocal<v8::Value> ffi, |
| 349 bool asPromise) { |
| 350 // Async cases are allowed, regardless of the size of the |
| 351 // wire bytes. Note that, for instantiation, we use the wire |
| 352 // bytes size as a proxy for instantiation time. We may |
| 353 // consider using the size of the ffi (nr of properties) |
| 354 // instead, or, even more directly, number of imports. |
| 355 if (asPromise) |
| 356 return true; |
| 357 // If it's not a promise, the source should be a wasm module |
| 358 DCHECK(source->IsWebAssemblyCompiledModule()); |
| 359 v8::Local<v8::WasmCompiledModule> module = |
| 360 v8::Local<v8::WasmCompiledModule>::Cast(source); |
| 361 if (static_cast<size_t>(module->GetWasmWireBytes()->Length()) > |
| 362 kWasmWireBytesLimit) { |
| 363 return false; |
| 364 } |
| 365 return true; |
| 366 } |
| 367 |
| 323 static void initializeV8Common(v8::Isolate* isolate) { | 368 static void initializeV8Common(v8::Isolate* isolate) { |
| 324 isolate->AddGCPrologueCallback(V8GCController::gcPrologue); | 369 isolate->AddGCPrologueCallback(V8GCController::gcPrologue); |
| 325 isolate->AddGCEpilogueCallback(V8GCController::gcEpilogue); | 370 isolate->AddGCEpilogueCallback(V8GCController::gcEpilogue); |
| 326 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { | 371 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { |
| 327 std::unique_ptr<ScriptWrappableVisitor> visitor( | 372 std::unique_ptr<ScriptWrappableVisitor> visitor( |
| 328 new ScriptWrappableVisitor(isolate)); | 373 new ScriptWrappableVisitor(isolate)); |
| 329 V8PerIsolateData::from(isolate)->setScriptWrappableVisitor( | 374 V8PerIsolateData::from(isolate)->setScriptWrappableVisitor( |
| 330 std::move(visitor)); | 375 std::move(visitor)); |
| 331 isolate->SetEmbedderHeapTracer( | 376 isolate->SetEmbedderHeapTracer( |
| 332 V8PerIsolateData::from(isolate)->scriptWrappableVisitor()); | 377 V8PerIsolateData::from(isolate)->scriptWrappableVisitor()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); | 453 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); |
| 409 isolate->AddMessageListenerWithErrorLevel( | 454 isolate->AddMessageListenerWithErrorLevel( |
| 410 messageHandlerInMainThread, | 455 messageHandlerInMainThread, |
| 411 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | 456 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 412 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | 457 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 413 v8::Isolate::kMessageLog); | 458 v8::Isolate::kMessageLog); |
| 414 isolate->SetFailedAccessCheckCallbackFunction( | 459 isolate->SetFailedAccessCheckCallbackFunction( |
| 415 failedAccessCheckCallbackInMainThread); | 460 failedAccessCheckCallbackInMainThread); |
| 416 isolate->SetAllowCodeGenerationFromStringsCallback( | 461 isolate->SetAllowCodeGenerationFromStringsCallback( |
| 417 codeGenerationCheckCallbackInMainThread); | 462 codeGenerationCheckCallbackInMainThread); |
| 418 | 463 isolate->SetAllowWasmCompileCallback(allowWasmCompileCallbackInMainThread); |
| 464 isolate->SetAllowWasmInstantiateCallback( |
| 465 allowWasmInstantiateCallbackInMainThread); |
| 419 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { | 466 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { |
| 420 V8PerIsolateData::enableIdleTasks( | 467 V8PerIsolateData::enableIdleTasks( |
| 421 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); | 468 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); |
| 422 } | 469 } |
| 423 | 470 |
| 424 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); | 471 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); |
| 425 | 472 |
| 426 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) | 473 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) |
| 427 profiler->SetWrapperClassInfoProvider( | 474 profiler->SetWrapperClassInfoProvider( |
| 428 WrapperTypeInfo::NodeClassId, &RetainedDOMInfo::createRetainedDOMInfo); | 475 WrapperTypeInfo::NodeClassId, &RetainedDOMInfo::createRetainedDOMInfo); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 v8::Isolate::kMessageLog); | 569 v8::Isolate::kMessageLog); |
| 523 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); | 570 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); |
| 524 | 571 |
| 525 uint32_t here; | 572 uint32_t here; |
| 526 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 573 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
| 527 kWorkerMaxStackSize); | 574 kWorkerMaxStackSize); |
| 528 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); | 575 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); |
| 529 } | 576 } |
| 530 | 577 |
| 531 } // namespace blink | 578 } // namespace blink |
| OLD | NEW |