From 7c88be65516f9d358fb7d46b4c347c170b384676 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sun, 8 May 2016 17:13:16 -0700 Subject: [PATCH] deps: added chakrashim apis for Proxy Added APIs `GetTarget()`, `GetHandler()` for Proxy. Today, there is no way to extract these fields through JSRT APIs, these APIs return `undefined` for now. I have opened microsoft/chakracore#950 to track this. Likewise, as per ES6 spec, there is no way to detect if an object is a Proxy hence `IsProxy()` too needs an equivalent JSRT API. PR-URL: #69 Reviewed-By: Jianchun Xu --- deps/chakrashim/chakrashim.gyp | 1 + deps/chakrashim/include/v8.h | 21 ++++++++++ deps/chakrashim/lib/chakra_shim.js | 4 ++ .../src/jsrtcachedpropertyidref.inc | 1 + deps/chakrashim/src/v8proxy.cc | 40 +++++++++++++++++++ deps/chakrashim/src/v8typedarray.cc | 12 ++++++ deps/chakrashim/src/v8value.cc | 1 + 7 files changed, 80 insertions(+) create mode 100644 deps/chakrashim/src/v8proxy.cc diff --git a/deps/chakrashim/chakrashim.gyp b/deps/chakrashim/chakrashim.gyp index a4d5884a2d9e69..6c4315b61930e2 100644 --- a/deps/chakrashim/chakrashim.gyp +++ b/deps/chakrashim/chakrashim.gyp @@ -101,6 +101,7 @@ 'src/v8objecttemplate.cc', 'src/v8persistent.cc', 'src/v8private.cc', + 'src/v8proxy.cc', 'src/v8script.cc', 'src/v8signature.cc', 'src/v8stacktrace.cc', diff --git a/deps/chakrashim/include/v8.h b/deps/chakrashim/include/v8.h index bcbdf112201121..8b73642c5b8afd 100644 --- a/deps/chakrashim/include/v8.h +++ b/deps/chakrashim/include/v8.h @@ -101,6 +101,7 @@ class Platform; class ResourceConstraints; class RegExp; class Promise; +class Proxy; class Script; class Signature; class StartupData; @@ -293,6 +294,7 @@ class Local { friend class ObjectData; friend class ObjectTemplate; friend class Private; + friend class Proxy; friend class Signature; friend class Script; friend class StackFrame; @@ -985,6 +987,7 @@ class V8_EXPORT Value : public Data { bool IsMap() const; bool IsSet() const; bool IsPromise() const; + bool IsProxy() const; V8_WARN_UNUSED_RESULT MaybeLocal ToBoolean( Local context) const; @@ -1677,6 +1680,24 @@ class V8_EXPORT Promise : public Object { Promise(); }; +class V8_EXPORT Proxy : public Object { +public: + Local GetTarget(); + Local GetHandler(); + bool IsRevoked(); + void Revoke(); + + static MaybeLocal New(Local context, + Local local_target, + Local local_handler); + + V8_INLINE static Proxy* Cast(Value* obj); + +private: + Proxy(); + static void CheckCast(Value* obj); +}; + enum class ArrayBufferCreationMode { kInternalized, kExternalized }; diff --git a/deps/chakrashim/lib/chakra_shim.js b/deps/chakrashim/lib/chakra_shim.js index e5ad86bf7c64aa..82645844a03d7b 100644 --- a/deps/chakrashim/lib/chakra_shim.js +++ b/deps/chakrashim/lib/chakra_shim.js @@ -521,6 +521,10 @@ utils.dequeueMicrotask = function(task) { return microTasks.shift(); }; + utils.isProxy = function(value) { + // CHAKRA-TODO: Need to add JSRT API to detect this + return false; + }; } patchErrorTypes(); diff --git a/deps/chakrashim/src/jsrtcachedpropertyidref.inc b/deps/chakrashim/src/jsrtcachedpropertyidref.inc index 655d8ac0b4522b..9563cfcc4ec46d 100644 --- a/deps/chakrashim/src/jsrtcachedpropertyidref.inc +++ b/deps/chakrashim/src/jsrtcachedpropertyidref.inc @@ -92,6 +92,7 @@ DEF_IS_TYPE(isDate) DEF_IS_TYPE(isMap) DEF_IS_TYPE(isNativeError) DEF_IS_TYPE(isPromise) +DEF_IS_TYPE(isProxy) DEF_IS_TYPE(isRegExp) DEF_IS_TYPE(isSet) DEF_IS_TYPE(isStringObject) diff --git a/deps/chakrashim/src/v8proxy.cc b/deps/chakrashim/src/v8proxy.cc new file mode 100644 index 00000000000000..9c53cc44c4b79c --- /dev/null +++ b/deps/chakrashim/src/v8proxy.cc @@ -0,0 +1,40 @@ +// Copyright Microsoft. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#include "v8chakra.h" + +namespace v8 { +Local Proxy::GetTarget() { + // CHAKRA-TODO: Need to add JSRT API to get target of proxy + JsValueRef undefinedValue = jsrt::GetUndefined(); + return Local::New(undefinedValue); +} + +Local Proxy::GetHandler() { + // CHAKRA-TODO: Need to add JSRT API to get handler of proxy + JsValueRef undefinedValue = jsrt::GetUndefined(); + return Local::New(undefinedValue); +} + +Proxy *Proxy::Cast(v8::Value *obj) { + CHAKRA_ASSERT(obj->IsProxy()); + return static_cast(obj); +} +} diff --git a/deps/chakrashim/src/v8typedarray.cc b/deps/chakrashim/src/v8typedarray.cc index 0de2703d05ef29..e1845a9e42549d 100644 --- a/deps/chakrashim/src/v8typedarray.cc +++ b/deps/chakrashim/src/v8typedarray.cc @@ -54,6 +54,18 @@ size_t ArrayBufferView::ByteLength() { return result; } +size_t TypedArray::Length() { + JsValueRef typedArrayRef = (JsValueRef)this; + int result; + if (jsrt::GetProperty(typedArrayRef, + IsolateShim::GetCurrent()->GetCachedPropertyIdRef + (jsrt::CachedPropertyIdRef::length), + &result) != JsNoError) { + return 0; + } + return result; +} + JsErrorCode Utils::NewTypedArray(ContextShim::GlobalType constructorIndex, Handle array_buffer, size_t byte_offset, size_t length, diff --git a/deps/chakrashim/src/v8value.cc b/deps/chakrashim/src/v8value.cc index 21c2ab18a73608..63e84b3becd73f 100644 --- a/deps/chakrashim/src/v8value.cc +++ b/deps/chakrashim/src/v8value.cc @@ -168,6 +168,7 @@ IS_TYPE_FUNCTION(IsDate, isDate) IS_TYPE_FUNCTION(IsMap, isMap) IS_TYPE_FUNCTION(IsNativeError, isNativeError) IS_TYPE_FUNCTION(IsPromise, isPromise) +IS_TYPE_FUNCTION(IsProxy, isProxy) IS_TYPE_FUNCTION(IsRegExp, isRegExp) IS_TYPE_FUNCTION(IsSet, isSet) IS_TYPE_FUNCTION(IsStringObject, isStringObject)