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

Side by Side Diff: Source/bindings/v8/ScriptPromise.cpp

Issue 337053004: Don't assert when ServiceWorker::from is passed an empty promise (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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) 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 if (!value->IsPromise()) { 60 if (!value->IsPromise()) {
61 m_promise = ScriptValue(scriptState, v8::Handle<v8::Value>()); 61 m_promise = ScriptValue(scriptState, v8::Handle<v8::Value>());
62 V8ThrowException::throwTypeError("the given value is not a Promise", scr iptState->isolate()); 62 V8ThrowException::throwTypeError("the given value is not a Promise", scr iptState->isolate());
63 return; 63 return;
64 } 64 }
65 m_promise = ScriptValue(scriptState, value); 65 m_promise = ScriptValue(scriptState, value);
66 } 66 }
67 67
68 ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOw nPtr<ScriptFunction> onRejected) 68 ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOw nPtr<ScriptFunction> onRejected)
69 { 69 {
70 v8::Local<v8::Function> v8OnFulfilled = ScriptFunction::adoptByGarbageCollec tor(onFulfilled);
71 v8::Local<v8::Function> v8OnRejected = ScriptFunction::adoptByGarbageCollect or(onRejected);
haraken 2014/06/17 00:51:55 Would you elaborate on this change? It seems a bit
falken 2014/06/17 01:07:51 The destructor of PassOwnPtr deletes the ScriptFun
haraken 2014/06/17 01:15:25 Thanks for the details; that ASSERT doesn't make m
72
70 if (m_promise.isEmpty()) 73 if (m_promise.isEmpty())
71 return ScriptPromise(); 74 return ScriptPromise();
72 75
73 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); 76 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>();
74 v8::Local<v8::Function> v8OnFulfilled = ScriptFunction::adoptByGarbageCollec tor(onFulfilled);
75 v8::Local<v8::Function> v8OnRejected = ScriptFunction::adoptByGarbageCollect or(onRejected);
76
77 ASSERT(promise->IsPromise()); 77 ASSERT(promise->IsPromise());
78 // Return this Promise if no handlers are given. 78 // Return this Promise if no handlers are given.
79 // In fact it is not the exact bahavior of Promise.prototype.then 79 // In fact it is not the exact bahavior of Promise.prototype.then
80 // but that is not a problem in this case. 80 // but that is not a problem in this case.
81 v8::Local<v8::Promise> resultPromise = promise.As<v8::Promise>(); 81 v8::Local<v8::Promise> resultPromise = promise.As<v8::Promise>();
82 // FIXME: Use Then once it is introduced. 82 // FIXME: Use Then once it is introduced.
83 if (!v8OnFulfilled.IsEmpty()) { 83 if (!v8OnFulfilled.IsEmpty()) {
84 resultPromise = resultPromise->Chain(v8OnFulfilled); 84 resultPromise = resultPromise->Chain(v8OnFulfilled);
85 if (resultPromise.IsEmpty()) { 85 if (resultPromise.IsEmpty()) {
86 // v8::Promise::Chain may return an empty value, for example when 86 // v8::Promise::Chain may return an empty value, for example when
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return promise; 127 return promise;
128 } 128 }
129 129
130 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa ssRefPtrWillBeRawPtr<DOMException> exception) 130 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa ssRefPtrWillBeRawPtr<DOMException> exception)
131 { 131 {
132 ASSERT(scriptState->isolate()->InContext()); 132 ASSERT(scriptState->isolate()->InContext());
133 return reject(scriptState, ToV8Value<WithScriptState, v8::Handle<v8::Object> >::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate( ))); 133 return reject(scriptState, ToV8Value<WithScriptState, v8::Handle<v8::Object> >::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate( )));
134 } 134 }
135 135
136 } // namespace WebCore 136 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698