| OLD | NEW |
| 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/DOMWrapperWorld.h" | 8 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 RELEASE_ASSERT(holder->IsObject()); | 184 RELEASE_ASSERT(holder->IsObject()); |
| 185 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder); | 185 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder); |
| 186 v8::Isolate* isolate = scriptState->isolate(); | 186 v8::Isolate* isolate = scriptState->isolate(); |
| 187 v8::Local<v8::Context> context = scriptState->context(); | 187 v8::Local<v8::Context> context = scriptState->context(); |
| 188 v8::Local<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate,
holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); | 188 v8::Local<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate,
holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); |
| 189 if (isInitialized.IsEmpty()) { | 189 if (isInitialized.IsEmpty()) { |
| 190 v8::TryCatch block; | 190 v8::TryCatch block; |
| 191 v8::Local<v8::Value> initializeFunction; | 191 v8::Local<v8::Value> initializeFunction; |
| 192 if (classObject->Get(scriptState->context(), v8String(isolate, "initiali
ze")).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) { | 192 if (classObject->Get(scriptState->context(), v8String(isolate, "initiali
ze")).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) { |
| 193 v8::TryCatch block; | 193 v8::TryCatch block; |
| 194 V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(initializ
eFunction), scriptState->executionContext(), holder, 0, 0, isolate); | 194 v8::Local<v8::Value> result; |
| 195 if (block.HasCaught()) { | 195 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(init
ializeFunction), scriptState->executionContext(), holder, 0, 0, isolate).ToLocal
(&result)) { |
| 196 fprintf(stderr, "Private script error: Object constructor threw
an exception.\n"); | 196 fprintf(stderr, "Private script error: Object constructor threw
an exception.\n"); |
| 197 dumpV8Message(context, block.Message()); | 197 dumpV8Message(context, block.Message()); |
| 198 RELEASE_ASSERT_NOT_REACHED(); | 198 RELEASE_ASSERT_NOT_REACHED(); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Inject the prototype object of the private script into the prototype
chain of the holder object. | 202 // Inject the prototype object of the private script into the prototype
chain of the holder object. |
| 203 // This is necessary to let the holder object use properties defined on
the prototype object | 203 // This is necessary to let the holder object use properties defined on
the prototype object |
| 204 // of the private script. (e.g., if the prototype object has |foo|, the
holder object should be able | 204 // of the private script. (e.g., if the prototype object has |foo|, the
holder object should be able |
| 205 // to use it with |this.foo|.) | 205 // to use it with |this.foo|.) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 fprintf(stderr, "Private script error: Target DOM attribute getter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); | 293 fprintf(stderr, "Private script error: Target DOM attribute getter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); |
| 294 RELEASE_ASSERT_NOT_REACHED(); | 294 RELEASE_ASSERT_NOT_REACHED(); |
| 295 } | 295 } |
| 296 v8::Local<v8::Value> getter; | 296 v8::Local<v8::Value> getter; |
| 297 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8
String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) { | 297 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8
String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) { |
| 298 fprintf(stderr, "Private script error: Target DOM attribute getter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); | 298 fprintf(stderr, "Private script error: Target DOM attribute getter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); |
| 299 RELEASE_ASSERT_NOT_REACHED(); | 299 RELEASE_ASSERT_NOT_REACHED(); |
| 300 } | 300 } |
| 301 initializeHolderIfNeeded(scriptState, classObject, holder); | 301 initializeHolderIfNeeded(scriptState, classObject, holder); |
| 302 v8::TryCatch block; | 302 v8::TryCatch block; |
| 303 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(v8::Local<v8::Fun
ction>::Cast(getter), scriptState->executionContext(), holder, 0, 0, isolate); | 303 v8::Local<v8::Value> result; |
| 304 if (block.HasCaught()) { | 304 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(getter), scr
iptState->executionContext(), holder, 0, 0, isolate).ToLocal(&result)) { |
| 305 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
ExceptionState::GetterContext, attributeName, className); | 305 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
ExceptionState::GetterContext, attributeName, className); |
| 306 block.ReThrow(); | 306 block.ReThrow(); |
| 307 return v8::Local<v8::Value>(); | 307 return v8::Local<v8::Value>(); |
| 308 } | 308 } |
| 309 return result; | 309 return result; |
| 310 } | 310 } |
| 311 | 311 |
| 312 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script
State* scriptStateInUserScript, const char* className, const char* attributeName
, v8::Local<v8::Value> holder, v8::Local<v8::Value> v8Value) | 312 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script
State* scriptStateInUserScript, const char* className, const char* attributeName
, v8::Local<v8::Value> holder, v8::Local<v8::Value> v8Value) |
| 313 { | 313 { |
| 314 v8::Isolate* isolate = scriptState->isolate(); | 314 v8::Isolate* isolate = scriptState->isolate(); |
| 315 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState,
className); | 315 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState,
className); |
| 316 v8::Local<v8::Value> descriptor; | 316 v8::Local<v8::Value> descriptor; |
| 317 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String(
isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) { | 317 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String(
isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) { |
| 318 fprintf(stderr, "Private script error: Target DOM attribute setter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); | 318 fprintf(stderr, "Private script error: Target DOM attribute setter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); |
| 319 RELEASE_ASSERT_NOT_REACHED(); | 319 RELEASE_ASSERT_NOT_REACHED(); |
| 320 } | 320 } |
| 321 v8::Local<v8::Value> setter; | 321 v8::Local<v8::Value> setter; |
| 322 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8
String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) { | 322 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8
String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) { |
| 323 fprintf(stderr, "Private script error: Target DOM attribute setter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); | 323 fprintf(stderr, "Private script error: Target DOM attribute setter was n
ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); |
| 324 RELEASE_ASSERT_NOT_REACHED(); | 324 RELEASE_ASSERT_NOT_REACHED(); |
| 325 } | 325 } |
| 326 initializeHolderIfNeeded(scriptState, classObject, holder); | 326 initializeHolderIfNeeded(scriptState, classObject, holder); |
| 327 v8::Local<v8::Value> argv[] = { v8Value }; | 327 v8::Local<v8::Value> argv[] = { v8Value }; |
| 328 v8::TryCatch block; | 328 v8::TryCatch block; |
| 329 V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(setter), scriptSt
ate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, isolate); | 329 v8::Local<v8::Value> result; |
| 330 if (block.HasCaught()) { | 330 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(setter), scr
iptState->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, isolate).ToL
ocal(&result)) { |
| 331 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
ExceptionState::SetterContext, attributeName, className); | 331 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
ExceptionState::SetterContext, attributeName, className); |
| 332 block.ReThrow(); | 332 block.ReThrow(); |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 return true; | 335 return true; |
| 336 } | 336 } |
| 337 | 337 |
| 338 v8::Local<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState,
ScriptState* scriptStateInUserScript, const char* className, const char* method
Name, v8::Local<v8::Value> holder, int argc, v8::Local<v8::Value> argv[]) | 338 v8::Local<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState,
ScriptState* scriptStateInUserScript, const char* className, const char* method
Name, v8::Local<v8::Value> holder, int argc, v8::Local<v8::Value> argv[]) |
| 339 { | 339 { |
| 340 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState,
className); | 340 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState,
className); |
| 341 v8::Local<v8::Value> method; | 341 v8::Local<v8::Value> method; |
| 342 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate(
), methodName)).ToLocal(&method) || !method->IsFunction()) { | 342 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate(
), methodName)).ToLocal(&method) || !method->IsFunction()) { |
| 343 fprintf(stderr, "Private script error: Target DOM method was not found.
(Class name = %s, Method name = %s)\n", className, methodName); | 343 fprintf(stderr, "Private script error: Target DOM method was not found.
(Class name = %s, Method name = %s)\n", className, methodName); |
| 344 RELEASE_ASSERT_NOT_REACHED(); | 344 RELEASE_ASSERT_NOT_REACHED(); |
| 345 } | 345 } |
| 346 initializeHolderIfNeeded(scriptState, classObject, holder); | 346 initializeHolderIfNeeded(scriptState, classObject, holder); |
| 347 v8::TryCatch block; | 347 v8::TryCatch block; |
| 348 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(v8::Local<v8::Fun
ction>::Cast(method), scriptState->executionContext(), holder, argc, argv, scrip
tState->isolate()); | 348 v8::Local<v8::Value> result; |
| 349 if (block.HasCaught()) { | 349 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(method), scr
iptState->executionContext(), holder, argc, argv, scriptState->isolate()).ToLoca
l(&result)) { |
| 350 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta
teInUserScript, ExceptionState::ExecutionContext, methodName, className); | 350 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta
teInUserScript, ExceptionState::ExecutionContext, methodName, className); |
| 351 block.ReThrow(); | 351 block.ReThrow(); |
| 352 return v8::Local<v8::Value>(); | 352 return v8::Local<v8::Value>(); |
| 353 } | 353 } |
| 354 return result; | 354 return result; |
| 355 } | 355 } |
| 356 | 356 |
| 357 } // namespace blink | 357 } // namespace blink |
| OLD | NEW |