| OLD | NEW |
| (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 // TODO(domenic): auto-run js2c.py ReadableStream.js ReadableStream.cpp blink kS
treamsExtensionCode using GYP |
| 11 // Also check to make sure this (ab)use of #include is kosher. |
| 12 // Also should we include the build products in the checkout? Probably not? |
| 13 #include "./ReadableStream.cpp" |
| 14 |
| 15 // TODO(domenic): presubmit checks don't like include order here ("Alphabetical
sorting problem.") |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 const char kStreamsExtensionName[] = "blink/streams"; |
| 20 |
| 21 class StreamsExtensionImpl : public v8::Extension { |
| 22 public: |
| 23 StreamsExtensionImpl() : v8::Extension(kStreamsExtensionName, kStreamsEx
tensionCode) { } |
| 24 |
| 25 private: |
| 26 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 27 v8::Isolate* isolate, v8::Handle<v8::String> name) override |
| 28 { |
| 29 |
| 30 if (name->Equals(v8::String::NewFromUtf8(isolate, "SET_PRIVATE"))) { |
| 31 return v8::FunctionTemplate::New(isolate, SetPrivate); |
| 32 } |
| 33 if (name->Equals(v8::String::NewFromUtf8(isolate, "GET_PRIVATE"))) { |
| 34 return v8::FunctionTemplate::New(isolate, GetPrivate); |
| 35 } |
| 36 if (name->Equals(v8::String::NewFromUtf8(isolate, "HAS_PRIVATE"))) { |
| 37 return v8::FunctionTemplate::New(isolate, HasPrivate); |
| 38 } |
| 39 |
| 40 return v8::Handle<v8::FunctionTemplate>(); |
| 41 } |
| 42 |
| 43 static void GetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 44 { |
| 45 ASSERT(info.Length() == 2 && info[0]->IsObject() && info[1]->IsStrin
g()); |
| 46 |
| 47 auto isolate = info.GetIsolate(); |
| 48 v8::HandleScope scope(isolate); |
| 49 auto object = info[0].As<v8::Object>(); |
| 50 auto name = info[1].As<v8::String>(); |
| 51 |
| 52 auto privateSymbol = v8::Private::ForApi(isolate, name); |
| 53 auto value = object->GetPrivate(privateSymbol); |
| 54 |
| 55 info.GetReturnValue().Set(value); |
| 56 } |
| 57 |
| 58 static void HasPrivate(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 59 { |
| 60 ASSERT(info.Length() == 2 && info[0]->IsObject() && info[1]->IsStrin
g()); |
| 61 |
| 62 auto isolate = info.GetIsolate(); |
| 63 v8::HandleScope scope(isolate); |
| 64 auto object = info[0].As<v8::Object>(); |
| 65 auto name = info[1].As<v8::String>(); |
| 66 |
| 67 auto privateSymbol = v8::Private::ForApi(isolate, name); |
| 68 auto value = object->HasPrivate(privateSymbol); |
| 69 |
| 70 info.GetReturnValue().Set(value); |
| 71 } |
| 72 |
| 73 static void SetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 74 { |
| 75 ASSERT(info.Length() == 3 && info[0]->IsObject() && info[1]->IsStrin
g()); |
| 76 |
| 77 auto isolate = info.GetIsolate(); |
| 78 v8::HandleScope scope(isolate); |
| 79 auto object = info[0].As<v8::Object>(); |
| 80 auto name = info[1].As<v8::String>(); |
| 81 auto value = info[2]; |
| 82 |
| 83 auto privateSymbol = v8::Private::ForApi(isolate, name); |
| 84 object->SetPrivate(privateSymbol, value); |
| 85 } |
| 86 }; |
| 87 |
| 88 v8::Extension* WebStreams::CreateV8Extension() |
| 89 { |
| 90 return new StreamsExtensionImpl(); |
| 91 } |
| 92 |
| 93 } // namespace blink |
| OLD | NEW |