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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "wtf/PassOwnPtr.h" | 54 #include "wtf/PassOwnPtr.h" |
55 #include <v8.h> | 55 #include <v8.h> |
56 | 56 |
57 namespace WebCore { | 57 namespace WebCore { |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 v8::Local<v8::ObjectTemplate> cachedObjectTemplate(void* domTemplateKey, int int
ernalFieldCount, v8::Isolate* isolate) | 61 v8::Local<v8::ObjectTemplate> cachedObjectTemplate(void* domTemplateKey, int int
ernalFieldCount, v8::Isolate* isolate) |
62 { | 62 { |
63 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 63 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
64 WrapperWorldType currentWorldType = worldType(isolate); | 64 v8::Handle<v8::FunctionTemplate> functionDescriptor = data->existingDOMTempl
ate(domTemplateKey); |
65 v8::Handle<v8::FunctionTemplate> functionDescriptor = data->existingDOMTempl
ate(currentWorldType, domTemplateKey); | |
66 if (!functionDescriptor.IsEmpty()) | 65 if (!functionDescriptor.IsEmpty()) |
67 return functionDescriptor->InstanceTemplate(); | 66 return functionDescriptor->InstanceTemplate(); |
68 | 67 |
69 functionDescriptor = v8::FunctionTemplate::New(isolate); | 68 functionDescriptor = v8::FunctionTemplate::New(isolate); |
70 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc
eTemplate(); | 69 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc
eTemplate(); |
71 instanceTemplate->SetInternalFieldCount(internalFieldCount); | 70 instanceTemplate->SetInternalFieldCount(internalFieldCount); |
72 data->setDOMTemplate(currentWorldType, domTemplateKey, functionDescriptor); | 71 data->setDOMTemplate(domTemplateKey, functionDescriptor); |
73 return instanceTemplate; | 72 return instanceTemplate; |
74 } | 73 } |
75 | 74 |
76 v8::Local<v8::ObjectTemplate> promiseAllEnvironmentObjectTemplate(v8::Isolate* i
solate) | 75 v8::Local<v8::ObjectTemplate> promiseAllEnvironmentObjectTemplate(v8::Isolate* i
solate) |
77 { | 76 { |
78 static int domTemplateKey; // This address is used for a key to look up the
dom template. | 77 static int domTemplateKey; // This address is used for a key to look up the
dom template. |
79 return cachedObjectTemplate(&domTemplateKey, V8PromiseCustom::PromiseAllEnvi
ronmentFieldCount, isolate); | 78 return cachedObjectTemplate(&domTemplateKey, V8PromiseCustom::PromiseAllEnvi
ronmentFieldCount, isolate); |
80 } | 79 } |
81 | 80 |
82 v8::Local<v8::ObjectTemplate> primitiveWrapperObjectTemplate(v8::Isolate* isolat
e) | 81 v8::Local<v8::ObjectTemplate> primitiveWrapperObjectTemplate(v8::Isolate* isolat
e) |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 void V8PromiseCustom::setState(v8::Handle<v8::Object> internal, PromiseState sta
te, v8::Handle<v8::Value> value, v8::Isolate* isolate) | 673 void V8PromiseCustom::setState(v8::Handle<v8::Object> internal, PromiseState sta
te, v8::Handle<v8::Value> value, v8::Isolate* isolate) |
675 { | 674 { |
676 ASSERT(!value.IsEmpty()); | 675 ASSERT(!value.IsEmpty()); |
677 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state
== Following); | 676 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state
== Following); |
678 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta
te)); | 677 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta
te)); |
679 internal->SetInternalField(InternalResultIndex, value); | 678 internal->SetInternalField(InternalResultIndex, value); |
680 } | 679 } |
681 | 680 |
682 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*
isolate) | 681 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*
isolate) |
683 { | 682 { |
684 WrapperWorldType currentWorldType = worldType(isolate); | 683 return V8Promise::domTemplate(isolate)->HasInstance(maybePromise); |
685 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP
romise); | |
686 } | 684 } |
687 | 685 |
688 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm
ise, v8::Isolate* isolate) | 686 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm
ise, v8::Isolate* isolate) |
689 { | 687 { |
690 // FIXME: Currently we don't check [[PromiseConstructor]] since we limit | 688 // FIXME: Currently we don't check [[PromiseConstructor]] since we limit |
691 // the creation of the promise objects only from the Blink Promise | 689 // the creation of the promise objects only from the Blink Promise |
692 // constructor. | 690 // constructor. |
693 if (isPromise(maybePromise, isolate)) | 691 if (isPromise(maybePromise, isolate)) |
694 return maybePromise.As<v8::Object>(); | 692 return maybePromise.As<v8::Object>(); |
695 | 693 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 831 |
834 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) | 832 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) |
835 { | 833 { |
836 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 834 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
837 ExecutionContext* executionContext = currentExecutionContext(isolate); | 835 ExecutionContext* executionContext = currentExecutionContext(isolate); |
838 ASSERT(executionContext && executionContext->isContextThread()); | 836 ASSERT(executionContext && executionContext->isContextThread()); |
839 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); | 837 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); |
840 } | 838 } |
841 | 839 |
842 } // namespace WebCore | 840 } // namespace WebCore |
OLD | NEW |