Provides an additionalGlobal initialization option

Summary:
Release Note: none

This PR should provide external tooling, that wraps Prepack Node, the ability to define Prepack globals. This will allow the React compiler to use standalone Prepack with the only differences being specific globals that are added (for React related stubs).

The `additionalGlobals` is a function that passes through `realm` like other globals are handled.
Closes https://github.com/facebook/prepack/pull/1073

Differential Revision: D6039946

Pulled By: trueadm

fbshipit-source-id: f38155244d8d3836b56f39fe964ed0f13b198621
This commit is contained in:
Dominic Gannaway 2017-10-13 13:31:40 -07:00 committed by Facebook Github Bot
parent cfc6993e9c
commit 52d274f78e
2 changed files with 5 additions and 0 deletions

View File

@ -11,8 +11,10 @@
import type { ErrorHandler } from "./errors.js";
import type { SerializerOptions, RealmOptions, Compatibility } from "./options";
import { Realm } from "./realm.js";
export type PrepackOptions = {|
additionalGlobals?: Realm => void,
additionalFunctions?: Array<string>,
compatibility?: Compatibility,
debugNames?: boolean,

View File

@ -44,6 +44,9 @@ export function prepackSources(
realmOptions.errorHandler = options.errorHandler;
let realm = construct_realm(realmOptions);
initializeGlobals(realm);
if (typeof options.additionalGlobals === "function") {
options.additionalGlobals(realm);
}
if (options.serialize || !options.residual) {
let serializer = new Serializer(realm, getSerializerOptions(options));