Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Make calls to native constructors return intrinsic objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed May 9, 2017
1 parent 6ed4775 commit 9634a7e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/intrinsics/node/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import invariant from "../../invariant.js";
import type { Realm } from "../../realm.js";
import { ConcreteValue, ArrayValue, ObjectValue, BooleanValue, NumberValue, StringValue, FunctionValue, NativeFunctionValue } from "../../values/index.js";
import { DefinePropertyOrThrow, OrdinaryDelete, OrdinaryDefineOwnProperty, ToString, ToInteger, ToBoolean } from "../../methods/index.js";
import { Get, DefinePropertyOrThrow, OrdinaryDelete, OrdinaryDefineOwnProperty, ToString, ToInteger, ToBoolean } from "../../methods/index.js";
import { TypesDomain, ValuesDomain } from "../../domains/index.js";
import buildExpressionTemplate from "../../utils/builder.js";
import initializeBuffer from "./buffer.js";
Expand Down Expand Up @@ -93,14 +93,27 @@ function initializeTTYWrap(realm) {
// let nativeTTY = nativeTTYWrap.TTY;
let obj = new ObjectValue(realm, realm.intrinsics.ObjectPrototype, "process.binding('tty_wrap')");

let constructor = new NativeFunctionValue(realm, "process.binding('tty_wrap').TTY", "TTY", 0, (context, args) => {
let constructor = new NativeFunctionValue(realm, "process.binding('tty_wrap').TTY", "TTY", 0, (context, args, argCount, NewTarget) => {
invariant(args[0] instanceof ConcreteValue);
// let fd = ToInteger(realm, args[0]);
let fd = ToInteger(realm, args[0]);
invariant(args[1] instanceof ConcreteValue);
// let value =
ToBoolean(realm, args[1]);
// TODO
return realm.intrinsics.undefined;
let value = ToBoolean(realm, args[1]);

invariant(NewTarget, "TTY must be called as a constructor.");

let proto = Get(realm, NewTarget, new StringValue(realm, "prototype"));
if (!(proto instanceof ObjectValue)) {
proto = TTYPrototype;
}

// TODO: Store nativeTTY in an internal slot so that it can be used if this
// object gets passed to another native call.

return new ObjectValue(
realm,
proto,
`new (process.binding('tty_wrap').TTY)(${fd}, ${value.toString()})`
);
});
OrdinaryDefineOwnProperty(realm, obj, "TTY", {
value: constructor,
Expand All @@ -121,7 +134,7 @@ function initializeTTYWrap(realm) {
// let req = args[0];
let content = args[1];
invariant(content instanceof StringValue);
console.log('TTYwriteUtf8String:', content.value);
// TODO: Store this as a side-effect.
return realm.intrinsics.undefined;
});

Expand Down

0 comments on commit 9634a7e

Please sign in to comment.