OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 v8::Local<v8::Context> context = isolate->GetCallingContext(); | 694 v8::Local<v8::Context> context = isolate->GetCallingContext(); |
695 if (context.IsEmpty()) { | 695 if (context.IsEmpty()) { |
696 // Unfortunately, when processing script from a plugin, we might not | 696 // Unfortunately, when processing script from a plugin, we might not |
697 // have a calling context. In those cases, we fall back to the | 697 // have a calling context. In those cases, we fall back to the |
698 // entered context. | 698 // entered context. |
699 context = isolate->GetEnteredContext(); | 699 context = isolate->GetEnteredContext(); |
700 } | 700 } |
701 return toLocalDOMWindow(toDOMWindow(context)); | 701 return toLocalDOMWindow(toDOMWindow(context)); |
702 } | 702 } |
703 | 703 |
704 namespace { | |
705 ExecutionContext* (*s_toExecutionContextForModules)(v8::Local<v8::Context>) = nu llptr; | |
706 } | |
707 | |
704 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) | 708 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) |
705 { | 709 { |
706 if (context.IsEmpty()) | 710 if (context.IsEmpty()) |
707 return 0; | 711 return 0; |
708 v8::Local<v8::Object> global = context->Global(); | 712 v8::Local<v8::Object> global = context->Global(); |
709 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain (global, context->GetIsolate()); | 713 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain (global, context->GetIsolate()); |
710 if (!windowWrapper.IsEmpty()) | 714 if (!windowWrapper.IsEmpty()) |
711 return V8Window::toImpl(windowWrapper)->executionContext(); | 715 return V8Window::toImpl(windowWrapper)->executionContext(); |
712 v8::Local<v8::Object> workerWrapper = V8WorkerGlobalScope::findInstanceInPro totypeChain(global, context->GetIsolate()); | 716 v8::Local<v8::Object> workerWrapper = V8WorkerGlobalScope::findInstanceInPro totypeChain(global, context->GetIsolate()); |
713 if (!workerWrapper.IsEmpty()) | 717 if (!workerWrapper.IsEmpty()) |
714 return V8WorkerGlobalScope::toImpl(workerWrapper)->executionContext(); | 718 return V8WorkerGlobalScope::toImpl(workerWrapper)->executionContext(); |
715 // FIXME: Is this line of code reachable? | 719 RELEASE_ASSERT(s_toExecutionContextForModules); |
haraken
2016/01/12 00:38:49
This is a performance-sensitive path, so let's use
ikilpatrick
2016/01/12 04:11:24
Done.
| |
716 return 0; | 720 return (*s_toExecutionContextForModules)(context); |
721 } | |
722 | |
723 void registerToExecutionContextForModules(ExecutionContext* (*toExecutionContext ForModules)(v8::Local<v8::Context>)) | |
724 { | |
725 s_toExecutionContextForModules = toExecutionContextForModules; | |
717 } | 726 } |
718 | 727 |
719 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) | 728 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) |
720 { | 729 { |
721 return toExecutionContext(isolate->GetCurrentContext()); | 730 return toExecutionContext(isolate->GetCurrentContext()); |
722 } | 731 } |
723 | 732 |
724 ExecutionContext* callingExecutionContext(v8::Isolate* isolate) | 733 ExecutionContext* callingExecutionContext(v8::Isolate* isolate) |
725 { | 734 { |
726 v8::Local<v8::Context> context = isolate->GetCallingContext(); | 735 v8::Local<v8::Context> context = isolate->GetCallingContext(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 result.setSmall(storage, length); | 779 result.setSmall(storage, length); |
771 } | 780 } |
772 | 781 |
773 v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld& w orld) | 782 v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld& w orld) |
774 { | 783 { |
775 ASSERT(context); | 784 ASSERT(context); |
776 if (context->isDocument()) { | 785 if (context->isDocument()) { |
777 if (LocalFrame* frame = toDocument(context)->frame()) | 786 if (LocalFrame* frame = toDocument(context)->frame()) |
778 return toV8Context(frame, world); | 787 return toV8Context(frame, world); |
779 } else if (context->isWorkerGlobalScope()) { | 788 } else if (context->isWorkerGlobalScope()) { |
780 if (WorkerOrWorkletScriptController* script = toWorkerGlobalScope(contex t)->script()) { | 789 if (WorkerOrWorkletScriptController* script = toWorkerOrWorkletGlobalSco pe(context)->script()) { |
781 if (script->scriptState()->contextIsValid()) | 790 if (script->scriptState()->contextIsValid()) |
782 return script->scriptState()->context(); | 791 return script->scriptState()->context(); |
783 } | 792 } |
784 } | 793 } |
785 return v8::Local<v8::Context>(); | 794 return v8::Local<v8::Context>(); |
786 } | 795 } |
787 | 796 |
788 v8::Local<v8::Context> toV8Context(Frame* frame, DOMWrapperWorld& world) | 797 v8::Local<v8::Context> toV8Context(Frame* frame, DOMWrapperWorld& world) |
789 { | 798 { |
790 if (!frame) | 799 if (!frame) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1020 v8::Local<v8::Value> data = info.Data(); | 1029 v8::Local<v8::Value> data = info.Data(); |
1021 ASSERT(data->IsExternal()); | 1030 ASSERT(data->IsExternal()); |
1022 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); | 1031 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); |
1023 if (!perContextData) | 1032 if (!perContextData) |
1024 return; | 1033 return; |
1025 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); | 1034 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); |
1026 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); | 1035 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); |
1027 } | 1036 } |
1028 | 1037 |
1029 } // namespace blink | 1038 } // namespace blink |
OLD | NEW |