Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp

Issue 2335203006: Add [CachedAccessor] attribute to cache (almost) constant accessors (window.document). (Closed)
Patch Set: Pre-review nits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "platform/RuntimeEnabledFeatures.h" 58 #include "platform/RuntimeEnabledFeatures.h"
59 #include "platform/ScriptForbiddenScope.h" 59 #include "platform/ScriptForbiddenScope.h"
60 #include "platform/TraceEvent.h" 60 #include "platform/TraceEvent.h"
61 #include "platform/heap/Handle.h" 61 #include "platform/heap/Handle.h"
62 #include "platform/weborigin/SecurityOrigin.h" 62 #include "platform/weborigin/SecurityOrigin.h"
63 #include "public/platform/Platform.h" 63 #include "public/platform/Platform.h"
64 #include "wtf/Assertions.h" 64 #include "wtf/Assertions.h"
65 #include "wtf/StringExtras.h" 65 #include "wtf/StringExtras.h"
66 #include "wtf/text/CString.h" 66 #include "wtf/text/CString.h"
67 #include <algorithm> 67 #include <algorithm>
68 #include <map>
68 #include <utility> 69 #include <utility>
69 #include <v8-debug.h> 70 #include <v8-debug.h>
70 #include <v8.h> 71 #include <v8.h>
71 72
72 namespace blink { 73 namespace blink {
73 74
74 static void checkDocumentWrapper(v8::Local<v8::Object> wrapper, Document* docume nt) 75 static void checkDocumentWrapper(v8::Local<v8::Object> wrapper, Document* docume nt)
75 { 76 {
76 ASSERT(V8Document::toImpl(wrapper) == document); 77 ASSERT(V8Document::toImpl(wrapper) == document);
77 } 78 }
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 LocalFrame* frame = toLocalFrame(m_frame); 404 LocalFrame* frame = toLocalFrame(m_frame);
404 v8::Local<v8::Value> documentWrapper = toV8(frame->document(), context->Glob al(), context->GetIsolate()); 405 v8::Local<v8::Value> documentWrapper = toV8(frame->document(), context->Glob al(), context->GetIsolate());
405 if (documentWrapper.IsEmpty()) 406 if (documentWrapper.IsEmpty())
406 return; 407 return;
407 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty()); 408 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty());
408 if (m_document.isEmpty()) 409 if (m_document.isEmpty())
409 updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper)); 410 updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
410 checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document()); 411 checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());
411 412
412 ASSERT(documentWrapper->IsObject()); 413 ASSERT(documentWrapper->IsObject());
413 // TODO(jochen): Don't replace the accessor with a data value. We need a way to tell v8 that the accessor's return value won't change after this point. 414
414 if (!v8CallBoolean(context->Global()->ForceSet(context, v8AtomicString(m_iso late, "document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadO nly | v8::DontDelete)))) 415 // Update cache.
415 return; 416 v8::Local<v8::Private> priv = cachedAccessors().at("Window#document").Get(m_ isolate);
Yuki 2016/09/15 08:17:34 Can you use V8PrivateProperty? I think std::map a
Alfonso 2016/09/16 14:21:48 Done.
417
418 // TODO(peterssen): This should be probably constant.
419 // static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)
420 CHECK(context->Global()->ForceSet(context, v8::Private::AsSymbol(priv), docu mentWrapper).FromJust());
jochen (gone - plz use gerrit) 2016/09/15 08:20:51 why forceset?
Alfonso 2016/09/16 14:21:47 Done.
416 } 421 }
417 422
418 void WindowProxy::updateActivityLogger() 423 void WindowProxy::updateActivityLogger()
419 { 424 {
420 m_scriptState->perContextData()->setActivityLogger(V8DOMActivityLogger::acti vityLogger( 425 m_scriptState->perContextData()->setActivityLogger(V8DOMActivityLogger::acti vityLogger(
421 m_world->worldId(), m_frame->isLocalFrame() && toLocalFrame(m_frame)->do cument() ? toLocalFrame(m_frame)->document()->baseURI() : KURL())); 426 m_world->worldId(), m_frame->isLocalFrame() && toLocalFrame(m_frame)->do cument() ? toLocalFrame(m_frame)->document()->baseURI() : KURL()));
422 } 427 }
423 428
424 void WindowProxy::setSecurityToken(SecurityOrigin* origin) 429 void WindowProxy::setSecurityToken(SecurityOrigin* origin)
425 { 430 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 558 }
554 559
555 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) 560 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin)
556 { 561 {
557 if (!isContextInitialized()) 562 if (!isContextInitialized())
558 return; 563 return;
559 setSecurityToken(origin); 564 setSecurityToken(origin);
560 } 565 }
561 566
562 } // namespace blink 567 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698