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

Side by Side Diff: Source/bindings/core/v8/V8PerContextData.cpp

Issue 1067763002: bindings: Use Maybe version of Get in bindings/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/ScriptState.h" 34 #include "bindings/core/v8/ScriptState.h"
35 #include "bindings/core/v8/V8Binding.h" 35 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8ObjectConstructor.h" 36 #include "bindings/core/v8/V8ObjectConstructor.h"
37 #include "wtf/StringExtras.h" 37 #include "wtf/StringExtras.h"
38 38
39 #include <stdlib.h> 39 #include <stdlib.h>
40 40
41 namespace blink { 41 namespace blink {
42 42
43 V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context) 43 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context)
44 : m_isolate(context->GetIsolate()) 44 : m_isolate(context->GetIsolate())
45 , m_wrapperBoilerplates(m_isolate) 45 , m_wrapperBoilerplates(m_isolate)
46 , m_constructorMap(m_isolate) 46 , m_constructorMap(m_isolate)
47 , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate))) 47 , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate)))
48 , m_context(m_isolate, context) 48 , m_context(m_isolate, context)
49 , m_activityLogger(0) 49 , m_activityLogger(0)
50 , m_compiledPrivateScript(m_isolate) 50 , m_compiledPrivateScript(m_isolate)
51 { 51 {
52 m_contextHolder->SetContext(context); 52 m_contextHolder->SetContext(context);
53 53
54 v8::Context::Scope contextScope(context); 54 v8::Context::Scope contextScope(context);
55 ASSERT(m_errorPrototype.isEmpty()); 55 ASSERT(m_errorPrototype.isEmpty());
56 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global ()->Get(v8AtomicString(m_isolate, "Error"))); 56 v8::Local<v8::Value> objectValue = context->Global()->Get(context, v8AtomicS tring(m_isolate, "Error")).ToLocalChecked();
57 ASSERT(!object.IsEmpty()); 57 ASSERT(objectValue->IsObject());
haraken 2015/04/07 08:56:43 This ASSERT won't be needed, since the following A
bashi 2015/04/07 09:37:31 Removed.
58 v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype")); 58 v8::Local<v8::Value> prototypeValue = objectValue.As<v8::Object>()->Get(cont ext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked();
59 ASSERT(!prototypeValue.IsEmpty());
60 m_errorPrototype.set(m_isolate, prototypeValue); 59 m_errorPrototype.set(m_isolate, prototypeValue);
61 } 60 }
62 61
63 V8PerContextData::~V8PerContextData() 62 V8PerContextData::~V8PerContextData()
64 { 63 {
65 } 64 }
66 65
67 PassOwnPtr<V8PerContextData> V8PerContextData::create(v8::Handle<v8::Context> co ntext) 66 PassOwnPtr<V8PerContextData> V8PerContextData::create(v8::Local<v8::Context> con text)
68 { 67 {
69 return adoptPtr(new V8PerContextData(context)); 68 return adoptPtr(new V8PerContextData(context));
70 } 69 }
71 70
72 V8PerContextData* V8PerContextData::from(v8::Handle<v8::Context> context) 71 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context)
73 { 72 {
74 return ScriptState::from(context)->perContextData(); 73 return ScriptState::from(context)->perContextData();
75 } 74 }
76 75
77 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra pperTypeInfo* type) 76 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra pperTypeInfo* type)
78 { 77 {
79 ASSERT(!m_errorPrototype.isEmpty()); 78 ASSERT(!m_errorPrototype.isEmpty());
80 79
81 v8::Context::Scope scope(context()); 80 v8::Context::Scope scope(context());
82 v8::Local<v8::Function> function = constructorForType(type); 81 v8::Local<v8::Function> function = constructorForType(type);
(...skipping 21 matching lines...) Expand all
104 return v8::Local<v8::Function>(); 103 return v8::Local<v8::Function>();
105 104
106 if (type->parentClass) { 105 if (type->parentClass) {
107 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren tClass); 106 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren tClass);
108 if (prototypeTemplate.IsEmpty()) 107 if (prototypeTemplate.IsEmpty())
109 return v8::Local<v8::Function>(); 108 return v8::Local<v8::Function>();
110 if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTempl ate))) 109 if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTempl ate)))
111 return v8::Local<v8::Function>(); 110 return v8::Local<v8::Function>();
112 } 111 }
113 112
114 v8::Local<v8::Value> prototypeValue = function->Get(v8AtomicString(m_isolate , "prototype")); 113 v8::Local<v8::Value> prototypeValue;
115 if (!prototypeValue.IsEmpty() && prototypeValue->IsObject()) { 114 if (function->Get(currentContext, v8AtomicString(m_isolate, "prototype")).To Local(&prototypeValue) && prototypeValue->IsObject()) {
bashi 2015/04/07 09:37:31 Chatted offline and we think it would be better to
116 v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prot otypeValue); 115 v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prot otypeValue);
117 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcou nt 116 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcou nt
118 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectP rototype) 117 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectP rototype)
119 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd ex, const_cast<WrapperTypeInfo*>(type)); 118 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd ex, const_cast<WrapperTypeInfo*>(type));
120 type->installConditionallyEnabledMethods(prototypeObject, m_isolate); 119 type->installConditionallyEnabledMethods(prototypeObject, m_isolate);
121 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionP rototype) { 120 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionP rototype) {
122 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_e rrorPrototype.newLocal(m_isolate)))) 121 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_e rrorPrototype.newLocal(m_isolate))))
123 return v8::Local<v8::Function>(); 122 return v8::Local<v8::Function>();
bashi 2015/04/07 09:37:31 This would also be RELEASE_ASSERT_NOT_REACHED(), b
124 } 123 }
125 } 124 }
126 125
127 m_constructorMap.Set(type, function); 126 m_constructorMap.Set(type, function);
128 127
129 return function; 128 return function;
130 } 129 }
131 130
132 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo* type) 131 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo* type)
133 { 132 {
134 v8::Local<v8::Object> constructor = constructorForType(type); 133 v8::Local<v8::Object> constructor = constructorForType(type);
135 if (constructor.IsEmpty()) 134 if (constructor.IsEmpty())
136 return v8::Local<v8::Object>(); 135 return v8::Local<v8::Object>();
137 return constructor->Get(v8String(m_isolate, "prototype")).As<v8::Object>(); 136 v8::Local<v8::Value> prototypeValue;
137 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(& prototypeValue) || !prototypeValue->IsObject())
138 return v8::Local<v8::Object>();
139 return prototypeValue.As<v8::Object>();
138 } 140 }
139 141
140 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti on, PassOwnPtr<CustomElementBinding> binding) 142 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti on, PassOwnPtr<CustomElementBinding> binding)
141 { 143 {
142 m_customElementBindings.append(binding); 144 m_customElementBindings.append(binding);
143 } 145 }
144 146
145 v8::Handle<v8::Value> V8PerContextData::compiledPrivateScript(String className) 147 v8::Handle<v8::Value> V8PerContextData::compiledPrivateScript(String className)
146 { 148 {
147 return m_compiledPrivateScript.Get(className); 149 return m_compiledPrivateScript.Get(className);
148 } 150 }
149 151
150 void V8PerContextData::setCompiledPrivateScript(String className, v8::Handle<v8: :Value> compiledObject) 152 void V8PerContextData::setCompiledPrivateScript(String className, v8::Handle<v8: :Value> compiledObject)
151 { 153 {
152 m_compiledPrivateScript.Set(className, compiledObject); 154 m_compiledPrivateScript.Set(className, compiledObject);
153 } 155 }
154 156
155 } // namespace blink 157 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8PerContextData.h ('k') | Source/bindings/core/v8/V8PerIsolateData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698