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

Side by Side Diff: Source/core/testing/Internals.cpp

Issue 22470008: Implement ScriptPromise and ScriptFunction (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Protect the ScriptFunction with a strong ref Created 7 years, 4 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 21 matching lines...) Expand all
32 #include "InternalProfilers.h" 32 #include "InternalProfilers.h"
33 #include "InternalRuntimeFlags.h" 33 #include "InternalRuntimeFlags.h"
34 #include "InternalSettings.h" 34 #include "InternalSettings.h"
35 #include "LayerRect.h" 35 #include "LayerRect.h"
36 #include "LayerRectList.h" 36 #include "LayerRectList.h"
37 #include "MallocStatistics.h" 37 #include "MallocStatistics.h"
38 #include "MockPagePopupDriver.h" 38 #include "MockPagePopupDriver.h"
39 #include "RuntimeEnabledFeatures.h" 39 #include "RuntimeEnabledFeatures.h"
40 #include "TypeConversions.h" 40 #include "TypeConversions.h"
41 #include "bindings/v8/ExceptionState.h" 41 #include "bindings/v8/ExceptionState.h"
42 #include "bindings/v8/ScriptFunction.h"
43 #include "bindings/v8/ScriptPromise.h"
42 #include "bindings/v8/SerializedScriptValue.h" 44 #include "bindings/v8/SerializedScriptValue.h"
43 #include "bindings/v8/V8ThrowException.h" 45 #include "bindings/v8/V8ThrowException.h"
44 #include "core/animation/DocumentTimeline.h" 46 #include "core/animation/DocumentTimeline.h"
45 #include "core/css/StyleSheetContents.h" 47 #include "core/css/StyleSheetContents.h"
46 #include "core/css/resolver/StyleResolver.h" 48 #include "core/css/resolver/StyleResolver.h"
47 #include "core/css/resolver/ViewportStyleResolver.h" 49 #include "core/css/resolver/ViewportStyleResolver.h"
48 #include "core/dom/ClientRect.h" 50 #include "core/dom/ClientRect.h"
49 #include "core/dom/ClientRectList.h" 51 #include "core/dom/ClientRectList.h"
50 #include "core/dom/DOMStringList.h" 52 #include "core/dom/DOMStringList.h"
51 #include "core/dom/Document.h" 53 #include "core/dom/Document.h"
(...skipping 2020 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 if (!sharedContext) 2074 if (!sharedContext)
2073 return false; 2075 return false;
2074 sharedContext->getExtensions()->loseContextCHROMIUM(Extensions3D::GUILTY_CON TEXT_RESET_ARB, Extensions3D::INNOCENT_CONTEXT_RESET_ARB); 2076 sharedContext->getExtensions()->loseContextCHROMIUM(Extensions3D::GUILTY_CON TEXT_RESET_ARB, Extensions3D::INNOCENT_CONTEXT_RESET_ARB);
2075 // To prevent tests that call loseSharedGraphicsContext3D from being 2077 // To prevent tests that call loseSharedGraphicsContext3D from being
2076 // flaky, we call finish so that the context is guaranteed to be lost 2078 // flaky, we call finish so that the context is guaranteed to be lost
2077 // synchronously (i.e. before returning). 2079 // synchronously (i.e. before returning).
2078 sharedContext->finish(); 2080 sharedContext->finish();
2079 return true; 2081 return true;
2080 } 2082 }
2081 2083
2084 class AddOneCallback : public ScriptFunction {
2085 public:
2086 virtual ScriptValue call(ScriptValue value) OVERRIDE
2087 {
2088 v8::Local<v8::Value> v8Value = value.v8Value();
2089 ASSERT(v8Value->IsNumber());
2090 int intValue = v8Value.As<v8::Integer>()->Value();
2091 ScriptValue result = ScriptValue(v8::Integer::New(intValue + 1));
2092 return result;
2093 }
2094 private:
2095 virtual ~AddOneCallback() { }
2096 };
2097
2098 ScriptValue Internals::addOneToPromise(ScriptValue promiseValue)
2099 {
2100 ScriptPromise promise(promiseValue);
2101
2102 bool result = promise.then(adoptRef(new AddOneCallback()));
2103 ASSERT(result);
2104
2105 return promise.ResultPromise();
2082 } 2106 }
2107
2108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698