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

Side by Side Diff: Source/platform/streams/WebStreams.cpp

Issue 924713002: [WIP] ReadableStream V8 extension (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | public/platform/WebStreams.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "public/platform/WebStreams.h"
7
8 #include "wtf/Assertions.h"
9
10 namespace blink {
11
12 const char kStreamsExtensionName[] = "blink/streams";
13
14 // TODO use js2c.py in a gyp file somehow to externalize this into a .js file
15 // Apparently the presubmit checks hate multiline strings because they hate free dom
16 const char kStreamsExtensionCode[] = R"JSCODE(
17 'use strict';
18
19 native function SET_PRIVATE();
20 native function GET_PRIVATE();
21
22 this.ReadableStream = ReadableStream;
23
24 function ReadableStream(underlyingSource) {
25 if (underlyingSource === undefined) {
26 underlyingSource = {};
27 }
28
29 SET_PRIVATE(this, 'ReadableStream#underlyingSource', underlyingSource);
30 }
31
32 ReadableStream.prototype.logUnderlyingSource = function () {
33 console.log(GET_PRIVATE(this, 'ReadableStream#underlyingSource'));
34 };
35
36 )JSCODE";
37
38 class StreamsExtensionImpl : public v8::Extension {
39 public:
40 StreamsExtensionImpl() : v8::Extension(kStreamsExtensionName, kStreamsEx tensionCode) { }
41
42 private:
43 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
44 v8::Isolate* isolate, v8::Handle<v8::String> name) override
45 {
46
47 if (name->Equals(v8::String::NewFromUtf8(isolate, "SET_PRIVATE"))) {
48 return v8::FunctionTemplate::New(isolate, SetPrivate);
49 }
50 if (name->Equals(v8::String::NewFromUtf8(isolate, "GET_PRIVATE"))) {
51 return v8::FunctionTemplate::New(isolate, GetPrivate);
52 }
53
54 return v8::Handle<v8::FunctionTemplate>();
55 }
56
57 static void SetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info)
58 {
59 ASSERT(info.Length() == 3 && info[0]->IsObject() && info[1]->IsStrin g());
60
61 auto isolate = info.GetIsolate();
62 v8::HandleScope scope(isolate);
63 auto object = info[0].As<v8::Object>();
64 auto name = info[1].As<v8::String>();
65 auto value = info[2];
66
67 auto privateSymbol = v8::Private::ForApi(isolate, name);
68 object->SetPrivate(privateSymbol, value);
69 }
70
71 static void GetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info)
72 {
73 ASSERT(info.Length() == 2 && info[0]->IsObject() && info[1]->IsStrin g());
74
75 auto isolate = info.GetIsolate();
76 v8::HandleScope scope(isolate);
77 auto object = info[0].As<v8::Object>();
78 auto name = info[1].As<v8::String>();
79
80 auto privateSymbol = v8::Private::ForApi(isolate, name);
Dmitry Lomov (no reviews) 2015/02/13 16:39:56 Hmm I do not get it. Seems like you are creating a
81 auto value = object->GetPrivate(privateSymbol);
82
83 info.GetReturnValue().Set(value);
84 }
85 };
86
87 v8::Extension* WebStreams::CreateV8Extension()
88 {
89 return new StreamsExtensionImpl();
90 }
91
92 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | public/platform/WebStreams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698