Bind methods instead of using eval

Reviewed By: astreet

Differential Revision: D3417452

fbshipit-source-id: 437daa2dfcd01efb749465a94c1a72ce8a2cb315
This commit is contained in:
Alexander Blom
2016-06-21 10:08:31 -07:00
committed by Facebook Github Bot 0
parent cd542f0656
commit d63d4f0e9c
9 changed files with 101 additions and 49 deletions

View File

@@ -1,5 +1,7 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#include <folly/json.h>
#include "Value.h"
#include "JSCHelpers.h"
@@ -49,6 +51,11 @@ Value Value::fromJSON(JSContextRef ctx, const String& json) throw(JSException) {
return Value(ctx, result);
}
Value Value::fromDynamic(JSContextRef ctx, folly::dynamic value) throw(JSException) {
auto json = folly::toJson(value);
return fromJSON(ctx, String(json.c_str()));
}
Object Value::asObject() {
JSValueRef exn;
JSObjectRef jsObj = JSValueToObject(context(), m_value, &exn);
@@ -65,7 +72,11 @@ Object::operator Value() const {
return Value(m_context, m_obj);
}
Value Object::callAsFunction(int nArgs, JSValueRef args[]) {
Value Object::callAsFunction(std::initializer_list<JSValueRef> args) const {
return callAsFunction(args.size(), args.begin());
}
Value Object::callAsFunction(int nArgs, const JSValueRef args[]) const {
JSValueRef exn;
JSValueRef result = JSObjectCallAsFunction(m_context, m_obj, NULL, nArgs, args, &exn);
if (!result) {