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