Skip to content

Commit 167b0ff

Browse files
committed
src: added 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 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.
1 parent b0f0017 commit 167b0ff

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

deps/chakrashim/chakrashim.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
'src/v8objecttemplate.cc',
102102
'src/v8persistent.cc',
103103
'src/v8private.cc',
104+
'src/v8proxy.cc',
104105
'src/v8script.cc',
105106
'src/v8signature.cc',
106107
'src/v8stacktrace.cc',

deps/chakrashim/include/v8.h

+21
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Platform;
101101
class ResourceConstraints;
102102
class RegExp;
103103
class Promise;
104+
class Proxy;
104105
class Script;
105106
class Signature;
106107
class StartupData;
@@ -293,6 +294,7 @@ class Local {
293294
friend class ObjectData;
294295
friend class ObjectTemplate;
295296
friend class Private;
297+
friend class Proxy;
296298
friend class Signature;
297299
friend class Script;
298300
friend class StackFrame;
@@ -985,6 +987,7 @@ class V8_EXPORT Value : public Data {
985987
bool IsMap() const;
986988
bool IsSet() const;
987989
bool IsPromise() const;
990+
bool IsProxy() const;
988991

989992
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
990993
Local<Context> context) const;
@@ -1677,6 +1680,24 @@ class V8_EXPORT Promise : public Object {
16771680
Promise();
16781681
};
16791682

1683+
class V8_EXPORT Proxy : public Object {
1684+
public:
1685+
Local<Object> GetTarget();
1686+
Local<Value> GetHandler();
1687+
bool IsRevoked();
1688+
void Revoke();
1689+
1690+
static MaybeLocal<Proxy> New(Local<Context> context,
1691+
Local<Object> local_target,
1692+
Local<Object> local_handler);
1693+
1694+
V8_INLINE static Proxy* Cast(Value* obj);
1695+
1696+
private:
1697+
Proxy();
1698+
static void CheckCast(Value* obj);
1699+
};
1700+
16801701

16811702
enum class ArrayBufferCreationMode { kInternalized, kExternalized };
16821703

deps/chakrashim/lib/chakra_shim.js

+4
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@
521521
utils.dequeueMicrotask = function(task) {
522522
return microTasks.shift();
523523
};
524+
utils.isProxy = function(value) {
525+
// CHAKRA-TODO: Need to add JSRT API to detect this
526+
return false;
527+
};
524528
}
525529

526530
patchErrorTypes();

deps/chakrashim/src/jsrtcachedpropertyidref.inc

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ DEF_IS_TYPE(isDate)
9292
DEF_IS_TYPE(isMap)
9393
DEF_IS_TYPE(isNativeError)
9494
DEF_IS_TYPE(isPromise)
95+
DEF_IS_TYPE(isProxy)
9596
DEF_IS_TYPE(isRegExp)
9697
DEF_IS_TYPE(isSet)
9798
DEF_IS_TYPE(isStringObject)

deps/chakrashim/src/v8proxy.cc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright Microsoft. All rights reserved.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files(the "Software"), to
5+
// deal in the Software without restriction, including without limitation the
6+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
7+
// sell copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions :
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
// IN THE SOFTWARE.
20+
21+
#include "v8chakra.h"
22+
23+
namespace v8 {
24+
Local<Object> Proxy::GetTarget() {
25+
// CHAKRA-TODO: Need to add JSRT API to get target of proxy
26+
JsValueRef undefinedValue = jsrt::GetUndefined();
27+
return Local<Object>::New(undefinedValue);
28+
}
29+
30+
Local<Value> Proxy::GetHandler() {
31+
// CHAKRA-TODO: Need to add JSRT API to get handler of proxy
32+
JsValueRef undefinedValue = jsrt::GetUndefined();
33+
return Local<Value>::New(undefinedValue);
34+
}
35+
36+
Proxy *Proxy::Cast(v8::Value *obj) {
37+
CHAKRA_ASSERT(obj->IsProxy());
38+
return static_cast<Proxy*>(obj);
39+
}
40+
}

deps/chakrashim/src/v8typedarray.cc

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ size_t ArrayBufferView::ByteLength() {
5454
return result;
5555
}
5656

57+
size_t TypedArray::Length() {
58+
JsValueRef typedArrayRef = (JsValueRef)this;
59+
int result;
60+
if (jsrt::GetProperty(typedArrayRef,
61+
IsolateShim::GetCurrent()->GetCachedPropertyIdRef
62+
(jsrt::CachedPropertyIdRef::length),
63+
&result) != JsNoError) {
64+
return 0;
65+
}
66+
return result;
67+
}
68+
5769
JsErrorCode Utils::NewTypedArray(ContextShim::GlobalType constructorIndex,
5870
Handle<ArrayBuffer> array_buffer,
5971
size_t byte_offset, size_t length,

deps/chakrashim/src/v8value.cc

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ IS_TYPE_FUNCTION(IsDate, isDate)
168168
IS_TYPE_FUNCTION(IsMap, isMap)
169169
IS_TYPE_FUNCTION(IsNativeError, isNativeError)
170170
IS_TYPE_FUNCTION(IsPromise, isPromise)
171+
IS_TYPE_FUNCTION(IsProxy, isProxy)
171172
IS_TYPE_FUNCTION(IsRegExp, isRegExp)
172173
IS_TYPE_FUNCTION(IsSet, isSet)
173174
IS_TYPE_FUNCTION(IsStringObject, isStringObject)

0 commit comments

Comments
 (0)