mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-13 11:11:51 +08:00
Summary: This adds a new jsi API prepareJavaScript. This accepts the same parameters as evaluateJavaScript() but does not evaluate anything; instead it returns a new object PreparedJavaScript which can itself be evaluated, via the new API evaluatePreparedJavaScript(). There is a new empty class PreparedJavaScript which may be subclassed by each Runtime variant to store its particular prepared form. Reviewed By: mhorowitz Differential Revision: D10491585 fbshipit-source-id: 702b9e23f2ff03d71a8ab17efb7e154b16dd8e87
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
//
|
|
// This source code is licensed under the MIT license found in the
|
|
// LICENSE file in the root directory of this source tree.
|
|
|
|
#pragma once
|
|
|
|
#include <jsi/jsi.h>
|
|
|
|
namespace facebook {
|
|
namespace jsi {
|
|
|
|
class FileBuffer : public Buffer {
|
|
public:
|
|
FileBuffer(const std::string& path);
|
|
~FileBuffer();
|
|
|
|
size_t size() const override {
|
|
return size_;
|
|
}
|
|
|
|
const uint8_t* data() const override {
|
|
return data_;
|
|
}
|
|
|
|
private:
|
|
size_t size_;
|
|
uint8_t* data_;
|
|
};
|
|
|
|
// A trivial implementation of PreparedJavaScript that simply stores the source
|
|
// buffer and URL.
|
|
class SourceJavaScriptPreparation final : public jsi::PreparedJavaScript,
|
|
public jsi::Buffer {
|
|
std::shared_ptr<const jsi::Buffer> buf_;
|
|
std::string sourceURL_;
|
|
|
|
public:
|
|
SourceJavaScriptPreparation(
|
|
std::shared_ptr<const jsi::Buffer> buf,
|
|
std::string sourceURL)
|
|
: buf_(std::move(buf)), sourceURL_(std::move(sourceURL)) {}
|
|
|
|
const std::string& sourceURL() const {
|
|
return sourceURL_;
|
|
}
|
|
|
|
size_t size() const override {
|
|
return buf_->size();
|
|
}
|
|
const uint8_t* data() const override {
|
|
return buf_->data();
|
|
}
|
|
};
|
|
|
|
} // namespace jsi
|
|
} // namespace facebook
|