| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2011 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 void V8Window::locationAttributeGetterCustom( | 69 void V8Window::locationAttributeGetterCustom( |
| 70 const v8::PropertyCallbackInfo<v8::Value>& info) { | 70 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 71 v8::Isolate* isolate = info.GetIsolate(); | 71 v8::Isolate* isolate = info.GetIsolate(); |
| 72 v8::Local<v8::Object> holder = info.Holder(); | 72 v8::Local<v8::Object> holder = info.Holder(); |
| 73 | 73 |
| 74 DOMWindow* window = V8Window::toImpl(holder); | 74 DOMWindow* window = V8Window::toImpl(holder); |
| 75 Location* location = window->location(); | 75 Location* location = window->location(); |
| 76 DCHECK(location); | 76 DCHECK(location); |
| 77 | 77 |
| 78 // Keep the wrapper object for the return value alive as long as |this| | 78 // If we have already created a wrapper object in this world, returns it. |
| 79 // object is alive in order to save creation time of the wrapper object. | |
| 80 if (DOMDataStore::SetReturnValue(info.GetReturnValue(), location)) | 79 if (DOMDataStore::SetReturnValue(info.GetReturnValue(), location)) |
| 81 return; | 80 return; |
| 82 | 81 |
| 83 v8::Local<v8::Value> wrapper; | 82 v8::Local<v8::Value> wrapper; |
| 84 | 83 |
| 85 // Note that this check is gated on whether or not |window| is remote, not | 84 // Note that this check is gated on whether or not |window| is remote, not |
| 86 // whether or not |window| is cross-origin. If |window| is local, the | 85 // whether or not |window| is cross-origin. If |window| is local, the |
| 87 // |location| property must always return the same wrapper, even if the | 86 // |location| property must always return the same wrapper, even if the |
| 88 // cross-origin status changes by changing properties like |document.domain|. | 87 // cross-origin status changes by changing properties like |document.domain|. |
| 89 if (window->IsRemoteDOMWindow()) { | 88 if (window->IsRemoteDOMWindow()) { |
| 90 DOMWrapperWorld& world = DOMWrapperWorld::Current(isolate); | 89 DOMWrapperWorld& world = DOMWrapperWorld::Current(isolate); |
| 91 const auto* wrapper_type_info = location->GetWrapperTypeInfo(); | 90 const auto* wrapper_type_info = location->GetWrapperTypeInfo(); |
| 92 v8::Local<v8::Object> new_wrapper = | 91 v8::Local<v8::Object> new_wrapper = |
| 93 wrapper_type_info->domTemplate(isolate, world) | 92 wrapper_type_info->domTemplate(isolate, world) |
| 94 ->NewRemoteInstance() | 93 ->NewRemoteInstance() |
| 95 .ToLocalChecked(); | 94 .ToLocalChecked(); |
| 96 | 95 |
| 97 DCHECK(!DOMDataStore::ContainsWrapper(location, isolate)); | 96 DCHECK(!DOMDataStore::ContainsWrapper(location, isolate)); |
| 98 wrapper = V8DOMWrapper::AssociateObjectWithWrapper( | 97 wrapper = V8DOMWrapper::AssociateObjectWithWrapper( |
| 99 isolate, location, wrapper_type_info, new_wrapper); | 98 isolate, location, wrapper_type_info, new_wrapper); |
| 100 } else { | 99 } else { |
| 101 wrapper = ToV8(location, holder, isolate); | 100 wrapper = ToV8(location, holder, isolate); |
| 102 } | 101 } |
| 103 | 102 |
| 104 // Keep the wrapper object for the return value alive as long as |this| | |
| 105 // object is alive in order to save creation time of the wrapper object. | |
| 106 // | |
| 107 // TODO(dcheng): The hidden reference behavior is broken in many ways. We | |
| 108 // should be caching for all DOM attributes. Even if it's not critical for | |
| 109 // remote Location objects, we should clean this up to improve | |
| 110 // maintainability. In the long-term, this will be superseded by wrapper | |
| 111 // tracing. | |
| 112 V8PrivateProperty::GetSymbol(isolate, "KeepAlive#Window#location") | |
| 113 .Set(holder, wrapper); | |
| 114 | |
| 115 V8SetReturnValue(info, wrapper); | 103 V8SetReturnValue(info, wrapper); |
| 116 } | 104 } |
| 117 | 105 |
| 118 void V8Window::eventAttributeGetterCustom( | 106 void V8Window::eventAttributeGetterCustom( |
| 119 const v8::FunctionCallbackInfo<v8::Value>& info) { | 107 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 120 LocalDOMWindow* impl = ToLocalDOMWindow(V8Window::toImpl(info.Holder())); | 108 LocalDOMWindow* impl = ToLocalDOMWindow(V8Window::toImpl(info.Holder())); |
| 121 v8::Isolate* isolate = info.GetIsolate(); | 109 v8::Isolate* isolate = info.GetIsolate(); |
| 122 ExceptionState exception_state(isolate, ExceptionState::kGetterContext, | 110 ExceptionState exception_state(isolate, ExceptionState::kGetterContext, |
| 123 "Window", "event"); | 111 "Window", "event"); |
| 124 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, | 112 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if (items->HasExactlyOneItem()) { | 380 if (items->HasExactlyOneItem()) { |
| 393 V8SetReturnValueFast(info, items->item(0), window); | 381 V8SetReturnValueFast(info, items->item(0), window); |
| 394 return; | 382 return; |
| 395 } | 383 } |
| 396 V8SetReturnValueFast(info, items, window); | 384 V8SetReturnValueFast(info, items, window); |
| 397 return; | 385 return; |
| 398 } | 386 } |
| 399 } | 387 } |
| 400 | 388 |
| 401 } // namespace blink | 389 } // namespace blink |
| OLD | NEW |