Fix tests of splitted config feature
Summary: The following PR fixes the tests used in the javascript port (it modifies gentest.rb). These changes don't yet pass, it seems something is segfaulting somewhere. I have to check if it comes from nbind, the yoga library, or the node bridge itself. There's also some fails on the browser build, but it might be the same issue. Closes https://github.com/facebook/yoga/pull/487 Reviewed By: emilsjolander Differential Revision: D4778870 Pulled By: astreet fbshipit-source-id: 936fbca564ec89738c78e50c4402c53eb6867dec
This commit is contained in:
committed by
Facebook Github Bot
parent
91a34bb875
commit
36f6fa9861
42
javascript/sources/Config.cc
Normal file
42
javascript/sources/Config.cc
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include "./Config.hh"
|
||||
|
||||
/* static */ Config * Config::create(void)
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
|
||||
/* static */ void Config::destroy(Config * node)
|
||||
{
|
||||
delete node;
|
||||
}
|
||||
|
||||
Config::Config(void)
|
||||
: m_config(YGConfigNew())
|
||||
{
|
||||
}
|
||||
|
||||
Config::~Config(void)
|
||||
{
|
||||
YGConfigFree(m_config);
|
||||
}
|
||||
|
||||
void Config::setExperimentalFeatureEnabled(int feature, bool enabled)
|
||||
{
|
||||
YGConfigSetExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature), enabled);
|
||||
}
|
||||
|
||||
bool Config::isExperimentalFeatureEnabled(int feature) const
|
||||
{
|
||||
return YGConfigIsExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature));
|
||||
}
|
@@ -14,36 +14,39 @@
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
class Config {
|
||||
private:
|
||||
YGConfigRef m_config;
|
||||
|
||||
Config(void)
|
||||
: m_config(YGConfigNew())
|
||||
{}
|
||||
friend class Node;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
static Config * create(void)
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
static Config * create(void);
|
||||
|
||||
static void destroy(Config * config)
|
||||
{
|
||||
delete config;
|
||||
}
|
||||
static void destroy(Config * config);
|
||||
|
||||
~Config(void)
|
||||
{
|
||||
YGConfigFree(m_config);
|
||||
}
|
||||
private:
|
||||
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled)
|
||||
{
|
||||
YGConfigSetExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature), enabled);
|
||||
}
|
||||
Config(void);
|
||||
|
||||
Config(Config const &) = delete;
|
||||
public:
|
||||
|
||||
~Config(void);
|
||||
|
||||
public: // Prevent accidental copy
|
||||
|
||||
Config(Config const &) = delete;
|
||||
|
||||
Config const & operator=(Config const &) = delete;
|
||||
|
||||
public: // Setters
|
||||
|
||||
void setExperimentalFeatureEnabled(int feature, bool enabled);
|
||||
|
||||
public: // Getters
|
||||
|
||||
bool isExperimentalFeatureEnabled(int feature) const;
|
||||
|
||||
private:
|
||||
|
||||
YGConfigRef m_config;
|
||||
|
||||
Config const & operator=(Config const &) = delete;
|
||||
};
|
||||
|
@@ -26,9 +26,14 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
|
||||
return ygSize;
|
||||
}
|
||||
|
||||
/* static */ Node * Node::create(void)
|
||||
/* static */ Node * Node::createDefault(void)
|
||||
{
|
||||
return new Node();
|
||||
return new Node(nullptr);
|
||||
}
|
||||
|
||||
/* static */ Node * Node::createWithConfig(Config * config)
|
||||
{
|
||||
return new Node(config);
|
||||
}
|
||||
|
||||
/* static */ void Node::destroy(Node * node)
|
||||
@@ -41,8 +46,8 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
|
||||
return reinterpret_cast<Node *>(YGNodeGetContext(nodeRef));
|
||||
}
|
||||
|
||||
Node::Node(void)
|
||||
: m_node(YGNodeNew())
|
||||
Node::Node(Config * config)
|
||||
: m_node(config != nullptr ? YGNodeNewWithConfig(config->m_config) : YGNodeNew())
|
||||
, m_measureFunc(nullptr)
|
||||
{
|
||||
YGNodeSetContext(m_node, reinterpret_cast<void *>(this));
|
||||
|
@@ -24,8 +24,9 @@ class Node {
|
||||
|
||||
public:
|
||||
|
||||
static Node * create(void);
|
||||
static Node * create(Config * config);
|
||||
static Node * createDefault(void);
|
||||
static Node * createWithConfig(Config * config);
|
||||
|
||||
static void destroy(Node * node);
|
||||
|
||||
public:
|
||||
@@ -34,7 +35,7 @@ class Node {
|
||||
|
||||
private:
|
||||
|
||||
Node(void);
|
||||
Node(Config * config);
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -169,6 +169,22 @@ module.exports = function (bind, lib) {
|
||||
|
||||
}
|
||||
|
||||
patch(lib.Config.prototype, `free`, function () {
|
||||
|
||||
// Since we handle the memory allocation ourselves (via lib.Config.create), we also need to handle the deallocation
|
||||
|
||||
lib.Config.destroy(this);
|
||||
|
||||
});
|
||||
|
||||
patch(lib.Node, `create`, function (_, config) {
|
||||
|
||||
// We decide the constructor we want to call depending on the parameters
|
||||
|
||||
return config ? lib.Node.createWithConfig(config) : lib.Node.createDefault();
|
||||
|
||||
});
|
||||
|
||||
patch(lib.Node.prototype, `free`, function () {
|
||||
|
||||
// Since we handle the memory allocation ourselves (via lib.Node.create), we also need to handle the deallocation
|
||||
@@ -207,18 +223,6 @@ module.exports = function (bind, lib) {
|
||||
|
||||
});
|
||||
|
||||
function setExperimentalFeatureEnabled(... args) {
|
||||
|
||||
return lib.setExperimentalFeatureEnabled(... args);
|
||||
|
||||
}
|
||||
|
||||
function isExperimentalFeatureEnabled(... args) {
|
||||
|
||||
return lib.isExperimentalFeatureEnabled(... args);
|
||||
|
||||
}
|
||||
|
||||
function getInstanceCount(... args) {
|
||||
|
||||
return lib.getInstanceCount(... args);
|
||||
@@ -231,15 +235,13 @@ module.exports = function (bind, lib) {
|
||||
|
||||
return Object.assign({
|
||||
|
||||
Config: lib.Config,
|
||||
Node: lib.Node,
|
||||
|
||||
Layout,
|
||||
Size,
|
||||
Value,
|
||||
|
||||
setExperimentalFeatureEnabled,
|
||||
isExperimentalFeatureEnabled,
|
||||
|
||||
getInstanceCount
|
||||
|
||||
}, constants);
|
||||
|
@@ -16,8 +16,6 @@
|
||||
#include "./Config.hh"
|
||||
#include "./global.hh"
|
||||
|
||||
#define NBIND_DUPLICATE_POINTERS true
|
||||
|
||||
#include <nbind/nbind.h>
|
||||
|
||||
NBIND_GLOBAL()
|
||||
@@ -45,13 +43,18 @@ NBIND_CLASS(Value)
|
||||
NBIND_CLASS(Config)
|
||||
{
|
||||
method(create);
|
||||
|
||||
method(destroy);
|
||||
|
||||
method(setExperimentalFeatureEnabled);
|
||||
|
||||
method(isExperimentalFeatureEnabled);
|
||||
}
|
||||
|
||||
NBIND_CLASS(Node)
|
||||
{
|
||||
method(create);
|
||||
method(createDefault);
|
||||
method(createWithConfig);
|
||||
method(destroy);
|
||||
|
||||
method(reset);
|
||||
|
Reference in New Issue
Block a user