| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 v8::Local<v8::ArrayBufferView> buffer = value.As<v8::ArrayBufferView>(); | 779 v8::Local<v8::ArrayBufferView> buffer = value.As<v8::ArrayBufferView>(); |
| 780 if (!storage) { | 780 if (!storage) { |
| 781 result.setFull(V8ArrayBufferView::toImpl(buffer)); | 781 result.setFull(V8ArrayBufferView::toImpl(buffer)); |
| 782 return; | 782 return; |
| 783 } | 783 } |
| 784 size_t length = buffer->ByteLength(); | 784 size_t length = buffer->ByteLength(); |
| 785 buffer->CopyContents(storage, length); | 785 buffer->CopyContents(storage, length); |
| 786 result.setSmall(storage, length); | 786 result.setSmall(storage, length); |
| 787 } | 787 } |
| 788 | 788 |
| 789 static ScriptState* toScriptStateImpl(LocalFrame* frame, |
| 790 DOMWrapperWorld& world) { |
| 791 if (!frame) |
| 792 return nullptr; |
| 793 v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world); |
| 794 if (context.IsEmpty()) |
| 795 return nullptr; |
| 796 ScriptState* scriptState = ScriptState::from(context); |
| 797 if (!scriptState->contextIsValid()) |
| 798 return nullptr; |
| 799 DCHECK_EQ(frame, toLocalFrameIfNotDetached(context)); |
| 800 return scriptState; |
| 801 } |
| 802 |
| 789 v8::Local<v8::Context> toV8Context(ExecutionContext* context, | 803 v8::Local<v8::Context> toV8Context(ExecutionContext* context, |
| 790 DOMWrapperWorld& world) { | 804 DOMWrapperWorld& world) { |
| 791 ASSERT(context); | 805 ASSERT(context); |
| 792 if (context->isDocument()) { | 806 if (context->isDocument()) { |
| 793 if (LocalFrame* frame = toDocument(context)->frame()) | 807 if (LocalFrame* frame = toDocument(context)->frame()) |
| 794 return toV8Context(frame, world); | 808 return toV8Context(frame, world); |
| 795 } else if (context->isWorkerGlobalScope()) { | 809 } else if (context->isWorkerGlobalScope()) { |
| 796 if (WorkerOrWorkletScriptController* script = | 810 if (WorkerOrWorkletScriptController* script = |
| 797 toWorkerOrWorkletGlobalScope(context)->scriptController()) { | 811 toWorkerOrWorkletGlobalScope(context)->scriptController()) { |
| 798 if (script->getScriptState()->contextIsValid()) | 812 if (script->getScriptState()->contextIsValid()) |
| 799 return script->getScriptState()->context(); | 813 return script->getScriptState()->context(); |
| 800 } | 814 } |
| 801 } | 815 } |
| 802 return v8::Local<v8::Context>(); | 816 return v8::Local<v8::Context>(); |
| 803 } | 817 } |
| 804 | 818 |
| 805 v8::Local<v8::Context> toV8Context(LocalFrame* frame, DOMWrapperWorld& world) { | 819 v8::Local<v8::Context> toV8Context(LocalFrame* frame, DOMWrapperWorld& world) { |
| 806 if (!frame) | 820 ScriptState* scriptState = toScriptStateImpl(frame, world); |
| 821 if (!scriptState) |
| 807 return v8::Local<v8::Context>(); | 822 return v8::Local<v8::Context>(); |
| 808 v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world); | 823 return scriptState->context(); |
| 809 if (context.IsEmpty()) | |
| 810 return v8::Local<v8::Context>(); | |
| 811 ScriptState* scriptState = ScriptState::from(context); | |
| 812 if (scriptState->contextIsValid()) { | |
| 813 DCHECK_EQ(frame, toLocalFrameIfNotDetached(context)); | |
| 814 return scriptState->context(); | |
| 815 } | |
| 816 return v8::Local<v8::Context>(); | |
| 817 } | 824 } |
| 818 | 825 |
| 819 v8::Local<v8::Context> toV8ContextEvenIfDetached(LocalFrame* frame, | 826 v8::Local<v8::Context> toV8ContextEvenIfDetached(LocalFrame* frame, |
| 820 DOMWrapperWorld& world) { | 827 DOMWrapperWorld& world) { |
| 821 ASSERT(frame); | 828 ASSERT(frame); |
| 822 return frame->windowProxy(world)->contextIfInitialized(); | 829 return frame->windowProxy(world)->contextIfInitialized(); |
| 823 } | 830 } |
| 824 | 831 |
| 832 ScriptState* toScriptState(LocalFrame* frame, DOMWrapperWorld& world) { |
| 833 v8::HandleScope handleScope(toIsolate(frame)); |
| 834 return toScriptStateImpl(frame, world); |
| 835 } |
| 836 |
| 837 ScriptState* toScriptStateForMainWorld(LocalFrame* frame) { |
| 838 return toScriptState(frame, DOMWrapperWorld::mainWorld()); |
| 839 } |
| 840 |
| 825 bool isValidEnum(const String& value, | 841 bool isValidEnum(const String& value, |
| 826 const char** validValues, | 842 const char** validValues, |
| 827 size_t length, | 843 size_t length, |
| 828 const String& enumName, | 844 const String& enumName, |
| 829 ExceptionState& exceptionState) { | 845 ExceptionState& exceptionState) { |
| 830 for (size_t i = 0; i < length; ++i) { | 846 for (size_t i = 0; i < length; ++i) { |
| 831 // Avoid the strlen inside String::operator== (because of the StringView). | 847 // Avoid the strlen inside String::operator== (because of the StringView). |
| 832 if (WTF::equal(value.impl(), validValues[i])) | 848 if (WTF::equal(value.impl(), validValues[i])) |
| 833 return true; | 849 return true; |
| 834 } | 850 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), | 988 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), |
| 973 parsed, tryCatch)) { | 989 parsed, tryCatch)) { |
| 974 if (tryCatch.HasCaught()) | 990 if (tryCatch.HasCaught()) |
| 975 exceptionState.rethrowV8Exception(tryCatch.Exception()); | 991 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 976 } | 992 } |
| 977 | 993 |
| 978 return parsed; | 994 return parsed; |
| 979 } | 995 } |
| 980 | 996 |
| 981 } // namespace blink | 997 } // namespace blink |
| OLD | NEW |