| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 v8::Local<v8::ObjectTemplate> internalObjectTemplate(v8::Isolate* isolate) | 91 v8::Local<v8::ObjectTemplate> internalObjectTemplate(v8::Isolate* isolate) |
| 92 { | 92 { |
| 93 // This is only for getting a unique pointer which we can pass to privateTem
plate. | 93 // This is only for getting a unique pointer which we can pass to privateTem
plate. |
| 94 static int privateTemplateUniqueKey = 0; | 94 static int privateTemplateUniqueKey = 0; |
| 95 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Inte
rnalFieldCount, isolate); | 95 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Inte
rnalFieldCount, isolate); |
| 96 } | 96 } |
| 97 | 97 |
| 98 class PromiseTask : public ScriptExecutionContext::Task { | 98 class PromiseTask : public ScriptExecutionContext::Task { |
| 99 public: | 99 public: |
| 100 PromiseTask(v8::Handle<v8::Function> callback, v8::Handle<v8::Object> receiv
er, v8::Handle<v8::Value> result) | 100 PromiseTask(v8::Handle<v8::Function> callback, v8::Handle<v8::Object> receiv
er, v8::Handle<v8::Value> result, v8::Isolate* isolate) |
| 101 : m_callback(callback) | 101 : m_callback(isolate, callback) |
| 102 , m_receiver(receiver) | 102 , m_receiver(isolate, receiver) |
| 103 , m_result(result) | 103 , m_result(isolate, result) |
| 104 { | 104 { |
| 105 ASSERT(!m_callback.isEmpty()); | 105 ASSERT(!m_callback.isEmpty()); |
| 106 ASSERT(!m_receiver.isEmpty()); | 106 ASSERT(!m_receiver.isEmpty()); |
| 107 ASSERT(!m_result.isEmpty()); | 107 ASSERT(!m_result.isEmpty()); |
| 108 } | 108 } |
| 109 virtual ~PromiseTask() { } | 109 virtual ~PromiseTask() { } |
| 110 | 110 |
| 111 virtual void performTask(ScriptExecutionContext*) OVERRIDE; | 111 virtual void performTask(ScriptExecutionContext*) OVERRIDE; |
| 112 | 112 |
| 113 private: | 113 private: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 136 v8::Handle<v8::Context> v8Context = state->context(); | 136 v8::Handle<v8::Context> v8Context = state->context(); |
| 137 v8::Context::Scope scope(v8Context); | 137 v8::Context::Scope scope(v8Context); |
| 138 v8::Handle<v8::Value> args[] = { m_result.newLocal(isolate) }; | 138 v8::Handle<v8::Value> args[] = { m_result.newLocal(isolate) }; |
| 139 V8ScriptRunner::callFunction(m_callback.newLocal(isolate), context, m_receiv
er.newLocal(isolate), WTF_ARRAY_LENGTH(args), args, isolate); | 139 V8ScriptRunner::callFunction(m_callback.newLocal(isolate), context, m_receiv
er.newLocal(isolate), WTF_ARRAY_LENGTH(args), args, isolate); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 v8::Handle<v8::Value> postTask(v8::Handle<v8::Function> callback, v8::Handle<v8:
:Object> receiver, v8::Handle<v8::Value> value, v8::Isolate* isolate) | 142 v8::Handle<v8::Value> postTask(v8::Handle<v8::Function> callback, v8::Handle<v8:
:Object> receiver, v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 143 { | 143 { |
| 144 ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext()
; | 144 ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext()
; |
| 145 ASSERT(scriptExecutionContext && scriptExecutionContext->isContextThread()); | 145 ASSERT(scriptExecutionContext && scriptExecutionContext->isContextThread()); |
| 146 scriptExecutionContext->postTask(adoptPtr(new PromiseTask(callback, receiver
, value))); | 146 scriptExecutionContext->postTask(adoptPtr(new PromiseTask(callback, receiver
, value, isolate))); |
| 147 return v8::Undefined(isolate); | 147 return v8::Undefined(isolate); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void wrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& args) | 150 void wrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& args) |
| 151 { | 151 { |
| 152 v8::Isolate* isolate = args.GetIsolate(); | 152 v8::Isolate* isolate = args.GetIsolate(); |
| 153 ASSERT(!args.Data().IsEmpty()); | 153 ASSERT(!args.Data().IsEmpty()); |
| 154 v8::Local<v8::Object> environment = args.Data().As<v8::Object>(); | 154 v8::Local<v8::Object> environment = args.Data().As<v8::Object>(); |
| 155 v8::Local<v8::Value> result = v8::Undefined(isolate); | 155 v8::Local<v8::Value> result = v8::Undefined(isolate); |
| 156 if (args.Length() > 0) | 156 if (args.Length() > 0) |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 v8::TryCatch trycatch; | 638 v8::TryCatch trycatch; |
| 639 v8::Handle<v8::Value> args[] = { result }; | 639 v8::Handle<v8::Value> args[] = { result }; |
| 640 V8ScriptRunner::callFunction(function, getScriptExecutionContext(), rece
iver, WTF_ARRAY_LENGTH(args), args, isolate); | 640 V8ScriptRunner::callFunction(function, getScriptExecutionContext(), rece
iver, WTF_ARRAY_LENGTH(args), args, isolate); |
| 641 } else { | 641 } else { |
| 642 ASSERT(mode == Asynchronous); | 642 ASSERT(mode == Asynchronous); |
| 643 postTask(function, receiver, result, isolate); | 643 postTask(function, receiver, result, isolate); |
| 644 } | 644 } |
| 645 } | 645 } |
| 646 | 646 |
| 647 } // namespace WebCore | 647 } // namespace WebCore |
| OLD | NEW |