Skip to content

Commit

Permalink
Don't use folly::stringPrintf in jschelpers
Browse files Browse the repository at this point in the history
Reviewed By: mhorowitz

Differential Revision: D5146873

fbshipit-source-id: 99224b0091ee0ea28e5dd132bcc65203d2dc43a6
  • Loading branch information
javache authored and facebook-github-bot committed May 30, 2017
1 parent cd49a5b commit 2766103
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
10 changes: 0 additions & 10 deletions ReactCommon/jschelpers/JSCHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <functional>
#include <stdexcept>

#include <folly/String.h>
#include <jschelpers/JavaScriptCore.h>
#include <jschelpers/Value.h>

Expand All @@ -18,10 +17,6 @@ class JSException : public std::exception {
explicit JSException(const char* msg)
: msg_(msg) {}

template <typename... Args>
explicit JSException(const char* fmt, Args... args)
: msg_(folly::stringPrintf(fmt, args...)) {}

explicit JSException(JSContextRef ctx, JSValueRef exn, const char* msg) {
buildMessage(ctx, exn, nullptr, msg);
}
Expand All @@ -30,11 +25,6 @@ class JSException : public std::exception {
buildMessage(ctx, exn, sourceURL, nullptr);
}

template <typename... Args>
explicit JSException(JSContextRef ctx, JSValueRef exn, JSStringRef sourceURL, const char* fmt, Args... args) {
buildMessage(ctx, exn, sourceURL, folly::stringPrintf(fmt, args...).c_str());
}

const std::string& getStack() const {
return stack_;
}
Expand Down
20 changes: 13 additions & 7 deletions ReactCommon/jschelpers/Value.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2004-present Facebook. All Rights Reserved.

#include <folly/json.h>

#include "Value.h"

#include <folly/json.h>
#include <folly/Conv.h>

#include "JSCHelpers.h"
#include "JavaScriptCore.h"

Expand Down Expand Up @@ -40,7 +41,8 @@ std::string Value::toJSONString(unsigned indent) const {
Value Value::fromJSON(JSContextRef ctx, const String& json) {
auto result = JSC_JSValueMakeFromJSONString(ctx, json);
if (!result) {
throw JSException("Failed to create Value from JSON: %s", json.str().c_str());
throw JSException(folly::to<std::string>(
"Failed to create Value from JSON: ", json.str()).c_str());
}
return Value(ctx, result);
}
Expand Down Expand Up @@ -190,7 +192,8 @@ Value Object::getProperty(const String& propName) const {
JSValueRef exn;
JSValueRef property = JSC_JSObjectGetProperty(m_context, m_obj, propName, &exn);
if (!property) {
throw JSException(m_context, exn, nullptr, "Failed to get property '%s'", propName.str().c_str());
throw JSException(m_context, exn, folly::to<std::string>(
"Failed to get property '", propName.str(), "'").c_str());
}
return Value(m_context, property);
}
Expand All @@ -199,7 +202,8 @@ Value Object::getPropertyAtIndex(unsigned int index) const {
JSValueRef exn;
JSValueRef property = JSC_JSObjectGetPropertyAtIndex(m_context, m_obj, index, &exn);
if (!property) {
throw JSException(m_context, exn, nullptr, "Failed to get property at index %d", index);
throw JSException(m_context, exn, folly::to<std::string>(
"Failed to get property at index ", index).c_str());
}
return Value(m_context, property);
}
Expand All @@ -212,15 +216,17 @@ void Object::setProperty(const String& propName, const Value& value) {
JSValueRef exn = nullptr;
JSC_JSObjectSetProperty(m_context, m_obj, propName, value, kJSPropertyAttributeNone, &exn);
if (exn) {
throw JSException(m_context, exn, nullptr, "Failed to set property '%s'", propName.str().c_str());
throw JSException(m_context, exn, folly::to<std::string>(
"Failed to set property '", propName.str(), "'").c_str());
}
}

void Object::setPropertyAtIndex(unsigned int index, const Value& value) {
JSValueRef exn = nullptr;
JSC_JSObjectSetPropertyAtIndex(m_context, m_obj, index, value, &exn);
if (exn) {
throw JSException(m_context, exn, nullptr, "Failed to set property at index %d", index);
throw JSException(m_context, exn, folly::to<std::string>(
"Failed to set property at index ", index).c_str());
}
}

Expand Down

0 comments on commit 2766103

Please sign in to comment.