Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
deps: added chakrashim apis for Proxy
Browse files Browse the repository at this point in the history
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 chakra-core/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 <Jianchun.Xu@microsoft.com>
  • Loading branch information
kunalspathak committed May 11, 2016
1 parent ca75446 commit 7c88be6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions deps/chakrashim/chakrashim.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Platform;
class ResourceConstraints;
class RegExp;
class Promise;
class Proxy;
class Script;
class Signature;
class StartupData;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean> ToBoolean(
Local<Context> context) const;
Expand Down Expand Up @@ -1677,6 +1680,24 @@ class V8_EXPORT Promise : public Object {
Promise();
};

class V8_EXPORT Proxy : public Object {
public:
Local<Object> GetTarget();
Local<Value> GetHandler();
bool IsRevoked();
void Revoke();

static MaybeLocal<Proxy> New(Local<Context> context,
Local<Object> local_target,
Local<Object> local_handler);

V8_INLINE static Proxy* Cast(Value* obj);

private:
Proxy();
static void CheckCast(Value* obj);
};


enum class ArrayBufferCreationMode { kInternalized, kExternalized };

Expand Down
4 changes: 4 additions & 0 deletions deps/chakrashim/lib/chakra_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/jsrtcachedpropertyidref.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions deps/chakrashim/src/v8proxy.cc
Original file line number Diff line number Diff line change
@@ -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<Object> Proxy::GetTarget() {
// CHAKRA-TODO: Need to add JSRT API to get target of proxy
JsValueRef undefinedValue = jsrt::GetUndefined();
return Local<Object>::New(undefinedValue);
}

Local<Value> Proxy::GetHandler() {
// CHAKRA-TODO: Need to add JSRT API to get handler of proxy
JsValueRef undefinedValue = jsrt::GetUndefined();
return Local<Value>::New(undefinedValue);
}

Proxy *Proxy::Cast(v8::Value *obj) {
CHAKRA_ASSERT(obj->IsProxy());
return static_cast<Proxy*>(obj);
}
}
12 changes: 12 additions & 0 deletions deps/chakrashim/src/v8typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayBuffer> array_buffer,
size_t byte_offset, size_t length,
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/v8value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7c88be6

Please sign in to comment.