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

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

Issue 362993004: Implement Blink-in-JS for DOM attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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
« no previous file with comments | « Source/bindings/core/v8/PrivateScriptRunner.h ('k') | Source/bindings/core/v8/V8HiddenValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/PrivateScriptRunner.h" 6 #include "bindings/core/v8/PrivateScriptRunner.h"
7 7
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8PerContextData.h" 9 #include "bindings/core/v8/V8PerContextData.h"
10 #include "bindings/core/v8/V8ScriptRunner.h" 10 #include "bindings/core/v8/V8ScriptRunner.h"
(...skipping 22 matching lines...) Expand all
33 // by make_private_script.py. 33 // by make_private_script.py.
34 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { 34 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
35 if (className == kPrivateScriptSources[index].name) 35 if (className == kPrivateScriptSources[index].name)
36 break; 36 break;
37 } 37 }
38 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources)); 38 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources));
39 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size); 39 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size);
40 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source) , isolate); 40 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source) , isolate);
41 } 41 }
42 42
43 static v8::Handle<v8::Value> propertyValue(ScriptState* scriptState, String clas sName, String propertyName) 43 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className)
44 { 44 {
45 ASSERT(scriptState->perContextData()); 45 ASSERT(scriptState->perContextData());
46 ASSERT(scriptState->executionContext()); 46 ASSERT(scriptState->executionContext());
47 v8::Isolate* isolate = scriptState->isolate(); 47 v8::Isolate* isolate = scriptState->isolate();
48 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className); 48 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
49 if (compiledClass.IsEmpty()) { 49 if (compiledClass.IsEmpty()) {
50 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner"); 50 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner");
51 if (installedClasses.IsEmpty()) { 51 if (installedClasses.IsEmpty()) {
52 installedClasses = compilePrivateScript(isolate, "PrivateScriptRunne r"); 52 installedClasses = compilePrivateScript(isolate, "PrivateScriptRunne r");
53 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri ptRunner", installedClasses); 53 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri ptRunner", installedClasses);
54 } 54 }
55 RELEASE_ASSERT(!installedClasses.IsEmpty()); 55 RELEASE_ASSERT(!installedClasses.IsEmpty());
56 RELEASE_ASSERT(installedClasses->IsObject()); 56 RELEASE_ASSERT(installedClasses->IsObject());
57 57
58 compilePrivateScript(isolate, className); 58 compilePrivateScript(isolate, className);
59 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className)); 59 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className));
60 RELEASE_ASSERT(!compiledClass.IsEmpty()); 60 RELEASE_ASSERT(!compiledClass.IsEmpty());
61 RELEASE_ASSERT(compiledClass->IsObject()); 61 RELEASE_ASSERT(compiledClass->IsObject());
62 scriptState->perContextData()->setCompiledPrivateScript(className, compi ledClass); 62 scriptState->perContextData()->setCompiledPrivateScript(className, compi ledClass);
63 } 63 }
64 return v8::Handle<v8::Object>::Cast(compiledClass)->Get(v8String(isolate, pr opertyName)); 64 return v8::Handle<v8::Object>::Cast(compiledClass);
65 } 65 }
66 66
67 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , String className, String operationName, v8::Handle<v8::Value> holder, int argc , v8::Handle<v8::Value> argv[]) 67 // FIXME: Replace this method with a V8 API for getOwnPropertyDescriptor, once V 8 is rolled.
68 static v8::Handle<v8::Object> getOwnPropertyDescriptor(ScriptState* scriptState, v8::Handle<v8::Object> classObject, String name)
68 { 69 {
69 v8::Handle<v8::Value> operation = propertyValue(scriptState, className, oper ationName); 70 ASSERT(!scriptState->contextIsEmpty());
70 RELEASE_ASSERT(!operation.IsEmpty()); 71 v8::Handle<v8::Value> object = scriptState->context()->Global()->Get(v8Strin g(scriptState->isolate(), "Object"));
71 RELEASE_ASSERT(operation->IsFunction()); 72 RELEASE_ASSERT(!object.IsEmpty());
72 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(operation ), scriptState->executionContext(), holder, argc, argv, scriptState->isolate()); 73 RELEASE_ASSERT(object->IsObject());
74 v8::Handle<v8::Value> getOwnPropertyDescriptorFunction = v8::Handle<v8::Obje ct>::Cast(object)->Get(v8String(scriptState->isolate(), "getOwnPropertyDescripto r"));
75 RELEASE_ASSERT(!getOwnPropertyDescriptorFunction.IsEmpty());
76 RELEASE_ASSERT(getOwnPropertyDescriptorFunction->IsFunction());
77 v8::Handle<v8::Value> argv[] = { classObject, v8String(scriptState->isolate( ), name) };
78 v8::Handle<v8::Value> descriptor = V8ScriptRunner::callInternalFunction(v8:: Handle<v8::Function>::Cast(getOwnPropertyDescriptorFunction), object, WTF_ARRAY_ LENGTH(argv), argv, scriptState->isolate());
79 RELEASE_ASSERT(!descriptor.IsEmpty());
80 RELEASE_ASSERT(descriptor->IsObject());
81 return v8::Handle<v8::Object>::Cast(descriptor);
82 }
83
84 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Handle<v8::Ob ject> classObject, v8::Handle<v8::Value> holder)
85 {
86 RELEASE_ASSERT(!holder.IsEmpty());
87 RELEASE_ASSERT(holder->IsObject());
88 v8::Handle<v8::Object> holderObject = v8::Handle<v8::Object>::Cast(holder);
89 v8::Isolate* isolate = scriptState->isolate();
90 v8::Handle<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate));
arv (Not doing code reviews) 2014/07/09 15:48:22 Hidden values are slow. Can we use a private symbo
haraken 2014/07/09 15:59:09 We have a plan to replace the implementation of V8
91 if (isInitialized.IsEmpty()) {
92 v8::Handle<v8::Value> initializeFunction = classObject->Get(v8String(iso late, "constructor"));
93 if (!initializeFunction.IsEmpty()) {
94 RELEASE_ASSERT(initializeFunction->IsFunction());
95 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(initiali zeFunction), scriptState->executionContext(), holder, 0, 0, isolate);
96 isInitialized = v8Boolean(true, isolate);
97 V8HiddenValue::setHiddenValue(isolate, holderObject, V8HiddenValue:: privateScriptObjectIsInitialized(isolate), isInitialized);
98 }
99 }
100 }
101
102 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder)
103 {
104 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
105 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
106 v8::Handle<v8::Value> getter = descriptor->Get(v8String(scriptState->isolate (), "get"));
107 RELEASE_ASSERT(!getter.IsEmpty());
108 RELEASE_ASSERT(getter->IsFunction());
109 initializeHolderIfNeeded(scriptState, classObject, holder);
110 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate());
111 }
112
113 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value)
114 {
115 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
116 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
117 v8::Handle<v8::Value> setter = descriptor->Get(v8String(scriptState->isolate (), "set"));
118 RELEASE_ASSERT(!setter.IsEmpty());
119 RELEASE_ASSERT(setter->IsFunction());
120 initializeHolderIfNeeded(scriptState, classObject, holder);
121 v8::Handle<v8::Value> argv[] = { v8Value };
122 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late());
123 }
124
125 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , String className, String methodName, v8::Handle<v8::Value> holder, int argc, v 8::Handle<v8::Value> argv[])
126 {
127 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
128 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName));
129 RELEASE_ASSERT(!method.IsEmpty());
130 RELEASE_ASSERT(method->IsFunction());
131 initializeHolderIfNeeded(scriptState, classObject, holder);
132 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate());
73 } 133 }
74 134
75 } // namespace WebCore 135 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/PrivateScriptRunner.h ('k') | Source/bindings/core/v8/V8HiddenValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698